2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
22 import com.aventstack.extentreports.Status;
23 import java.time.Duration;
24 import java.util.List;
25 import lombok.AllArgsConstructor;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
29 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebDriver;
32 import org.openqa.selenium.WebElement;
33 import org.openqa.selenium.interactions.Actions;
36 * Represents the Composition Interface Operations Modal.
38 public class InterfaceDefinitionOperationsModal extends AbstractPageObject {
40 private InterfaceOperationInputListComponent inputListComponent;
41 private InterfaceOperationAddInputComponent addInputComponent;
43 public InterfaceDefinitionOperationsModal(final WebDriver webDriver) {
48 public void isLoaded() {
52 public void isLoaded(boolean isInViewMode) {
53 waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
54 waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
55 waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
56 waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
57 waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
58 this.inputListComponent = new InterfaceOperationInputListComponent(webDriver);
59 this.inputListComponent.isLoaded();
61 this.addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
62 this.addInputComponent.isLoaded();
66 private void clickOnSave() {
67 waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
70 public void clickOnCancel() {
71 waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
74 public void clickOnDelete() {
75 waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
78 public void deleteInput(String inputName) {
79 inputListComponent.loadInputList();
80 inputListComponent.deleteInput(inputName);
83 public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
84 fillDescription(interfaceOperationsData.getDescription());
85 fillImplementationName(interfaceOperationsData.getImplementationName());
86 interfaceOperationsData.getInputList().forEach(inputData -> {
87 final InterfaceOperationAddInputComponent addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
88 addInputComponent.isLoaded();
89 addInputComponent.clickOnAddInputLink();
90 addInputComponent.fillInput(inputData);
91 addInputComponent.clickOnAddButton();
92 ExtentTestActions.takeScreenshot(Status.INFO,
93 "compositionInterfaceOperationsModal.addInput." + inputData.getName(),
94 String.format("Input '%s' added", inputData.getName())
96 addInputComponent.fillValue(inputData);
99 //there is no feedback from the UI to check if the update was successful. Forcing a wait time trying to guarantee that,
100 // although time is never a guarantee in this case.
101 new Actions(webDriver).pause(Duration.ofSeconds(5)).perform();
104 private void fillDescription(final String description) {
105 setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
108 private void fillImplementationName(final String implementationName) {
109 setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
112 private void setInputField(final By locator, final String value) {
116 final WebElement webElement = findElement(locator);
118 webElement.sendKeys(value);
120 ExtentTestActions.takeScreenshot(Status.INFO, value, value);
123 public void clickOnAddInput() {
124 addInputComponent.clickOnAddInputLink();
127 public String getDescription() {
128 return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
131 public String getImplementationName() {
132 return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
135 public List<InputData> getInputs() {
136 inputListComponent.loadInputList();
137 return inputListComponent.getInputList();
141 private enum XpathSelector {
142 TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
143 DELETE_BTN("//svg-icon[@name='trash-o']"),
144 SAVE_BTN("//button[@data-tests-id='Save']"),
145 CANCEL_BTN("//button[@data-tests-id='Cancel']"),
146 INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
147 OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
148 INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
149 INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']");
151 private final String xPath;
153 public String getXPath(final String... xpathParams) {
154 return String.format(xPath, xpathParams);
160 public static class InterfaceOperationsData {
162 private final String description;
163 private final String implementationName;
164 private final List<InputData> inputList;
168 public static class InputData {
170 private final String name;
171 private final String type;
172 private final Object value;