Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / AttributeModal.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages;
21
22 import lombok.AllArgsConstructor;
23 import lombok.Getter;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.WebElement;
27
28 /**
29  * Handles the 'Attributes' Edit Modal UI actions
30  */
31 public class AttributeModal extends AbstractPageObject {
32
33     private WebElement wrappingElement;
34
35     public AttributeModal(final WebDriver webDriver) {
36         super(webDriver);
37     }
38
39     @Override
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()));
44     }
45
46     public void fillForm(final AttributeData attributeData, final boolean isUpdate) {
47         if (!isUpdate) {
48             editName(attributeData.getAttributeName());
49             editType(attributeData.getAttributeType());
50         }
51         editDescription(attributeData.getDescription());
52         editDefaultValue(attributeData.getDefaultValue());
53     }
54
55     private void editName(final String attributeName) {
56         final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTE_NAME_INPUT.getXPath()));
57         webElement.clear();
58         webElement.sendKeys(attributeName);
59     }
60
61     private void editDescription(final String description) {
62         final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.DESCRIPTION_INPUT.getXPath()));
63         webElement.clear();
64         webElement.sendKeys(description);
65     }
66
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();
71     }
72
73     private void editDefaultValue(final String defaultValue) {
74         final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.DEFAULT_VALUE_INPUT.getXPath()));
75         webElement.clear();
76         webElement.sendKeys(defaultValue);
77     }
78
79     public void clickSave() {
80         waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
81     }
82
83     @Getter
84     @AllArgsConstructor
85     public static class AttributeData {
86
87         private final String attributeName;
88         private final String description;
89         private final String attributeType;
90         private final String defaultValue;
91     }
92
93     /**
94      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
95      */
96     @AllArgsConstructor
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']");
108
109         @Getter
110         private final String xPath;
111
112         public String getXPath(final String... xpathParams) {
113             return String.format(xPath, xpathParams);
114         }
115
116     }
117
118 }