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;
35 import static org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils.waitForLoader;
38 * Represents the Composition Interface Operations Modal.
40 public class InterfaceDefinitionOperationsModal extends AbstractPageObject {
42 private InterfaceOperationInputListComponent inputListComponent;
43 private InterfaceOperationAddInputComponent addInputComponent;
45 public InterfaceDefinitionOperationsModal(final WebDriver webDriver) {
50 public void isLoaded() {
54 public void isLoaded(boolean isInViewMode) {
55 waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
56 waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
57 waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
58 waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
59 waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
60 this.inputListComponent = new InterfaceOperationInputListComponent(webDriver);
61 this.inputListComponent.isLoaded();
63 this.addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
64 this.addInputComponent.isLoaded();
68 public void isUnloaded() {
69 waitForElementInvisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
70 waitForElementInvisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
71 waitForElementInvisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
72 waitForElementInvisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
73 waitForElementInvisibility(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
76 private void clickOnSave() {
77 waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
80 public void clickOnCancel() {
81 waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
84 public void clickOnDelete() {
85 waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
88 public void deleteInput(String inputName) {
89 inputListComponent.loadInputList();
90 inputListComponent.deleteInput(inputName);
93 public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
94 fillDescription(interfaceOperationsData.getDescription());
95 fillImplementationName(interfaceOperationsData.getImplementationName());
96 interfaceOperationsData.getInputList().forEach(inputData -> {
97 final InterfaceOperationAddInputComponent addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
98 addInputComponent.isLoaded();
99 addInputComponent.clickOnAddInputLink();
100 addInputComponent.fillInput(inputData);
101 addInputComponent.clickOnAddButton();
102 ExtentTestActions.takeScreenshot(Status.INFO,
103 "compositionInterfaceOperationsModal.addInput." + inputData.getName(),
104 String.format("Input '%s' added", inputData.getName())
106 addInputComponent.fillValue(inputData);
112 private void fillDescription(final String description) {
113 setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
116 private void fillImplementationName(final String implementationName) {
117 setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
120 private void setInputField(final By locator, final String value) {
124 final WebElement webElement = findElement(locator);
126 webElement.sendKeys(value);
128 ExtentTestActions.takeScreenshot(Status.INFO, value, value);
131 public void clickOnAddInput() {
132 addInputComponent.clickOnAddInputLink();
135 public String getDescription() {
136 return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
139 public String getImplementationName() {
140 return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
143 public List<InputData> getInputs() {
144 inputListComponent.loadInputList();
145 return inputListComponent.getInputList();
149 private enum XpathSelector {
150 TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
151 DELETE_BTN("//svg-icon[@name='trash-o']"),
152 SAVE_BTN("//button[@data-tests-id='Save']"),
153 CANCEL_BTN("//button[@data-tests-id='Cancel']"),
154 INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
155 OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
156 INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
157 INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']");
159 private final String xPath;
161 public String getXPath(final String... xpathParams) {
162 return String.format(xPath, xpathParams);
168 public static class InterfaceOperationsData {
170 private final String description;
171 private final String implementationName;
172 private final List<InputData> inputList;
176 public static class InputData {
178 private final String name;
179 private final String type;
180 private final Object value;