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 lombok.AllArgsConstructor;
25 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
26 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.WebElement;
32 * Handles the add input inside the interface operation modal.
34 * @see "catalog-ui app-add-input component"
36 public class InterfaceOperationAddInputComponent extends AbstractPageObject {
38 public InterfaceOperationAddInputComponent(final WebDriver webDriver) {
43 public void isLoaded() {
44 waitForElementVisibility(XpathSelector.ADD_INPUT_LINK.getXPath());
48 * Clicks on the add input link, that opens the add input form.
50 public void clickOnAddInputLink() {
51 waitToBeClickable(By.xpath(XpathSelector.ADD_INPUT_LINK.getXPath())).click();
52 waitForElementVisibility(XpathSelector.NAME_INPUT.getXPath());
53 waitForElementVisibility(XpathSelector.TYPE_INPUT.getXPath());
54 waitForElementVisibility(XpathSelector.ADD_BTN.getXPath());
55 waitForElementVisibility(XpathSelector.CANCEL_BTN.getXPath());
59 * Clicks on the add button that submits the input form.
61 public void clickOnAddButton() {
62 waitToBeClickable(By.xpath(XpathSelector.ADD_BTN.getXPath())).click();
66 * Fills the input form fields with the given data.
68 * @param inputData the input information
70 public void fillInput(final InputData inputData) {
71 fillName(inputData.getName());
72 fillType(inputData.getType());
76 * Fills an input value, in the input list, based on the given input data.
78 * @param inputData the input information
80 public void fillValue(final InputData inputData) {
81 var interfaceOperationInputListComponent = new InterfaceOperationInputListComponent(webDriver);
82 interfaceOperationInputListComponent.isLoaded();
83 interfaceOperationInputListComponent.fillInputValue(inputData.getName(), inputData.getValue());
87 * Fills the input name field.
89 * @param name the name to fill
91 public void fillName(final String name) {
92 setInputValue(By.xpath(XpathSelector.NAME_INPUT.getXPath()), name);
96 * Fills the input type field.
98 * @param type the type to fill
100 public void fillType(final String type) {
101 final WebElement inputElement = findElement(By.xpath(XpathSelector.TYPE_INPUT.getXPath()));
102 inputElement.click();
103 waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_RESULTS.getXPath()));
104 inputElement.sendKeys(type);
105 waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_OPTION.getXPath(type))).click();
108 private void setInputValue(final By locator, final String value) {
113 final WebElement webElement = findElement(locator);
115 webElement.sendKeys(value);
119 private enum XpathSelector {
120 ADD_INPUT_LINK("//a[@data-tests-id='add-input.add-input-link']"),
121 NAME_INPUT("//input[@data-tests-id='add-input.input-name']"),
122 TYPE_INPUT("//input[starts-with(@data-tests-id, 'add-input.input-type')]"),
123 ADD_BTN("//button[@data-tests-id='add-input.add-input-btn']"),
124 CANCEL_BTN("//button[@data-tests-id='add-input.cancel-btn']"),
125 DROPDOWN_RESULTS("//dropdown-results"),
126 DROPDOWN_OPTION("//li[@data-tests-id='%s']");
128 private final String xPath;
130 public String getXPath(final String... xpathParams) {
131 return String.format(xPath, xpathParams);