3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Optional;
30 import lombok.AllArgsConstructor;
31 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
32 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
33 import org.openqa.selenium.By;
34 import org.openqa.selenium.WebDriver;
35 import org.openqa.selenium.WebElement;
38 * Handles the input list inside the interface operation modal.
40 * @see "catalog-ui app-input-list and app-input-list-item ui components"
42 public class InterfaceOperationInputListComponent extends AbstractPageObject {
44 private WebElement wrappingElement;
45 private List<WebElement> inputList = new ArrayList<>();
47 public InterfaceOperationInputListComponent(final WebDriver webDriver) {
52 public void isLoaded() {
53 this.wrappingElement = waitForElementVisibility(XpathSelector.WRAPPING_ELEMENT.getXPath());
58 * Loads the input list
60 public void loadInputList() {
61 this.inputList = findSubElements(wrappingElement, XpathSelector.INPUT_LIST.getXPath());
65 * Fill an input value.
67 * @param inputName the input name
68 * @param value the value
70 public void fillInputValue(final String inputName, final Object value) {
74 if (value instanceof String || value instanceof Integer || value instanceof Boolean) {
75 fillSimpleValue(inputName, String.valueOf(value));
78 throw new UnsupportedOperationException("Set input value not yet implemented for value type: " + value.getClass().getName());
82 * Expands or retracts an input in the input list.
84 * @param name the input name
86 public void toggleInputExpansion(final String name) {
87 final Optional<WebElement> inputOpt = findInput(name);
88 final By expandIconSelector = By.xpath(XpathSelector.EXPAND_ICON.getXPath());
89 inputOpt.ifPresent(webElement ->
90 webElement.findElement(expandIconSelector).click()
95 * Deletes an input from the input list.
97 * @param name the name of the input to delete
99 public void deleteInput(final String name) {
100 final Optional<WebElement> inputOpt = findInput(name);
101 final By deleteIconSelector = By.xpath(XpathSelector.DELETE_ICON.getXPath());
102 inputOpt.ifPresent(webElement ->
103 webElement.findElement(deleteIconSelector).click()
106 assertTrue(findInput(name).isEmpty());
109 public List<InputData> getInputList() {
110 if (inputList.isEmpty()) {
111 return Collections.emptyList();
113 final List<InputData> inputDataList = new ArrayList<>();
114 final By inputLabelSelector = By.xpath(XpathSelector.INPUT_LABEL.getXPath());
115 final By inputTypeSelector = By.xpath(XpathSelector.INPUT_TYPE.getXPath());
116 inputList.forEach(inputWebElement -> {
117 String inputLabel = inputWebElement.findElement(inputLabelSelector).getText();
118 inputLabel = inputLabel.substring(0, inputLabel.length() -1);
119 final String inputType = inputWebElement.findElement(inputTypeSelector).getText();
120 var inputData = new InputData(inputLabel, inputType, null);
121 inputDataList.add(inputData);
124 return inputDataList;
127 private Optional<WebElement> findInput(final String name) {
128 final String label = name + ":";
129 final By inputLabelSelector = By.xpath(XpathSelector.INPUT_LABEL.getXPath());
130 return inputList.stream().filter(webElement -> {
131 final WebElement inputLabel = webElement.findElement(inputLabelSelector);
132 return label.equals(inputLabel.getText());
136 private void fillSimpleValue(final String inputName, final String inputValue) {
137 toggleInputExpansion(inputName);
138 final Optional<WebElement> inputOpt = findInput(inputName);
139 assertTrue(inputOpt.isPresent(), String.format("Could not set value for input '%s'. The input was not found.", inputName));
140 final By simpleInputValueSelector = By.xpath(XpathSelector.SIMPLE_VALUE_INPUT_RELATIVE_FROM_INPUT_INFO.getXPath());
141 inputOpt.ifPresent(webElement -> webElement.findElement(simpleInputValueSelector).sendKeys(inputValue));
145 private enum XpathSelector {
146 WRAPPING_ELEMENT("//div[@class='input-tree']"),
147 INPUT_LIST("//div[@class='input-tree']/*/*/*/span[@class='input-info']"),
148 INPUT_LABEL("label[@class='input-label']"),
149 INPUT_TYPE("em[@data-tests-id='input-type']"),
150 SIMPLE_VALUE_INPUT_RELATIVE_FROM_INPUT_INFO("..//li[@class='input-value']/input"),
151 EXPAND_ICON("em[contains(concat(' ',normalize-space(@class),' '),' round-expand-icon ')]"),
152 DELETE_ICON("span[contains(concat(' ',normalize-space(@class),' '),' delete-btn ')]");
154 private final String xPath;
156 public String getXPath(final String... xpathParams) {
157 return String.format(xPath, xpathParams);