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;
22 import lombok.AllArgsConstructor;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.WebElement;
29 * Handles the 'Attributes' Edit Modal UI actions
31 public class AttributeModal extends AbstractPageObject {
33 private WebElement wrappingElement;
35 public AttributeModal(final WebDriver webDriver) {
40 public void isLoaded() {
41 waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXPath()));
42 waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
43 wrappingElement = findElement(By.xpath(XpathSelector.ATTR_CONTAINER_DIV.getXPath()));
46 public void fillForm(final AttributeData attributeData, final boolean isUpdate) {
48 editName(attributeData.getAttributeName());
49 editType(attributeData.getAttributeType());
51 editDescription(attributeData.getDescription());
52 editDefaultValue(attributeData.getDefaultValue());
55 private void editName(final String attributeName) {
56 final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTE_NAME_INPUT.getXPath()));
58 webElement.sendKeys(attributeName);
61 private void editDescription(final String description) {
62 final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.DESCRIPTION_INPUT.getXPath()));
64 webElement.sendKeys(description);
67 private void editType(final String attributeType) {
68 waitToBeClickable(By.xpath(XpathSelector.ATTRIBUT_TYPE_ICON.getXPath())).click();
69 final WebElement element = waitForElementVisibility(By.xpath(XpathSelector.DROPDOWN_RESULTS.getXPath()));
70 element.findElement(By.xpath(XpathSelector.ATTRIBUTE_TYPE_LI.getXPath(attributeType))).click();
73 private void editDefaultValue(final String defaultValue) {
74 final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.DEFAULT_VALUE_INPUT.getXPath()));
76 webElement.sendKeys(defaultValue);
79 public void clickSave() {
80 waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
85 public static class AttributeData {
87 private final String attributeName;
88 private final String description;
89 private final String attributeType;
90 private final String defaultValue;
94 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
97 private enum XpathSelector {
98 TITLE_DIV("//div[contains(@class,'title') and contains(text(), ' Attribute Details')]"),
99 ATTR_CONTAINER_DIV("//div[@class='attr-container']"),
100 ATTRIBUTE_NAME_INPUT("//input[@data-tests-id='attributeName']"),
101 DESCRIPTION_INPUT("//textarea[@data-tests-id='description']"),
102 ATTRIBUTE_TYPE_LI("//li[@data-tests-id='%s']"),
103 ATTRIBUT_TYPE_ICON("//div[@data-tests-id='attributeType-icon']"),
104 DROPDOWN_RESULTS("//ul[contains(@class,'dropdown-results')]"),
105 ATTRIBUTE_TYPE_DIV("//div[@data-tests-id='attributeType']"),
106 DEFAULT_VALUE_INPUT("//input[@data-tests-id='defaultValue']"),
107 SAVE_BTN("//button[@data-tests-id='button-save']");
110 private final String xPath;
112 public String getXPath(final String... xpathParams) {
113 return String.format(xPath, xpathParams);