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 / AttributesPage.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.onap.sdc.frontend.ci.tests.pages.AttributeModal.AttributeData;
25 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29
30 /**
31  * Handles the 'Attributes' Page UI actions
32  */
33 public class AttributesPage extends ComponentPage {
34
35     private WebElement wrappingElement;
36
37     public AttributesPage(final WebDriver webDriver) {
38         super(webDriver);
39     }
40
41     @Override
42     public void isLoaded() {
43         super.isLoaded();
44         waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()));
45         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
46         waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_DIV.getXpath()));
47         wrappingElement = findElement(By.xpath(XpathSelector.ATTRIBUTES_DIV.getXpath()));
48     }
49
50     public boolean isAttributePresent(final String attributeName) {
51         try {
52             final WebElement element = wrappingElement.findElement(By.xpath(XpathSelector.ATTRIBUTES_NAME_SPAN.getXpath(attributeName)));
53             return element != null;
54         } catch (final Exception e) {
55             return false;
56         }
57     }
58
59     public void addAttribute(final AttributeData attributeData) {
60         final AttributeModal attributeModal = clickOnAdd();
61         attributeModal.isLoaded();
62         attributeModal.fillForm(attributeData, false);
63         attributeModal.clickSave();
64         loaderHelper.waitForLoader(LoaderHelper.XpathSelector.SDC_LOADER_LARGE, 5);
65     }
66
67     public AttributeModal clickOnAdd() {
68         waitToBeClickable(By.xpath(XpathSelector.ADD_BTN.getXpath())).click();
69         return new AttributeModal(webDriver);
70     }
71
72     public AttributeModal clickOnEdit(final String attributeName) {
73         waitToBeClickable(By.xpath(XpathSelector.EDIT_BTN.getXpath(attributeName))).click();
74         return new AttributeModal(webDriver);
75     }
76
77     public void deleteAttribute(final String attributeName) {
78         if (attributeName == null) {
79             return;
80         }
81         waitForElementVisibility(By.xpath(XpathSelector.DELETE_BTN.getXpath(attributeName))).click();
82         waitToBeClickable(By.xpath(XpathSelector.DELETE_ATTRIBUTE_CONFIRM_BTN.getXpath())).click();
83         waitForElementInvisibility(By.xpath(XpathSelector.DELETE_BTN.getXpath(attributeName)), 5);
84     }
85
86     public void editAttribute(final AttributeData attributeData) {
87         final AttributeModal attributeModal = clickOnEdit(attributeData.getAttributeName());
88         attributeModal.isLoaded();
89         attributeModal.fillForm(attributeData, true);
90         attributeModal.clickSave();
91         loaderHelper.waitForLoader(LoaderHelper.XpathSelector.SDC_LOADER_LARGE, 5);
92     }
93
94     /**
95      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
96      */
97     @AllArgsConstructor
98     private enum XpathSelector {
99         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
100         TITLE_DIV("workspace-tab-title", "//div[contains(@class,'%s') and contains(text(), 'Attributes')]"),
101         ATTRIBUTES_DIV("workspace-attributes", "//div[@class='%s']"),
102         ADD_BTN("svg-icon-label", "//span[contains(@class,'%s') and contains(text(), 'Add')]"),
103         ATTRIBUTES_NAME_SPAN("//div[@data-tests-id='attrib-name_%s']"),
104         EDIT_BTN("//div[contains(@class,'svg-icon') and @data-tests-id='edit_%s']"),
105         DELETE_BTN("//div[contains(@class,'svg-icon') and @data-tests-id='delete_%s']"),
106         DELETE_ATTRIBUTE_CONFIRM_BTN("delete-modal-button-ok", "//button[@data-tests-id='%s']");
107
108         @Getter
109         private String id;
110         private final String xpathFormat;
111
112         XpathSelector(final String xpathFormat) {
113             this.xpathFormat = xpathFormat;
114         }
115
116         public String getXpath(final String... xpathParams) {
117             return String.format(xpathFormat, xpathParams);
118         }
119
120         public String getXpath() {
121             return String.format(xpathFormat, id);
122         }
123
124     }
125
126 }