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 / AttributesTabComponent.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 package org.onap.sdc.frontend.ci.tests.pages;
20
21 import lombok.AllArgsConstructor;
22 import lombok.Getter;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.WebDriver;
25 import org.openqa.selenium.WebElement;
26
27 /**
28  * Handles the 'Attributes' Tab UI component on 'Attributes & Outputs' Page
29  */
30 public class AttributesTabComponent extends AbstractPageObject {
31
32     public AttributesTabComponent(final WebDriver webDriver) {
33         super(webDriver);
34     }
35
36     @Override
37     public void isLoaded() {
38         waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_TABLE.getXpath()));
39         waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()));
40     }
41
42     public void declareOutput(final String attributeName) {
43         if (attributeName == null) {
44             return;
45         }
46         waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_CHECKBOX.getXpath(attributeName))).click();
47         waitToBeClickable(By.xpath(XpathSelector.DECLARE_OUTPUT_BTN.getXpath())).click();
48         final By setInputNameLocator = By.xpath(XpathSelector.SET_INPUT_NAME_FIELD.getXpath());
49         final WebElement inputNameField = waitForElementVisibility(setInputNameLocator, 5);
50         waitToBeClickable(By.xpath(XpathSelector.INPUT_NAME_SAVE_BTN.getXpath())).click();
51         waitForAddedOutputNotification();
52     }
53
54     private void waitForAddedOutputNotification() {
55         waitForElementVisibility(By.xpath(XpathSelector.ADDED_OUTPUT_NOTIFICATION.getXpath()));
56     }
57
58     /**
59      * Checks if a attribute exists.
60      *
61      * @return true if exists, false if not
62      */
63     public boolean isAttributePresent(final String attributeName) {
64         try {
65             waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_CHECKBOX.getXpath(attributeName)));
66         } catch (final Exception ignored) {
67             return false;
68         }
69         return true;
70     }
71
72     public boolean isInstanceSelected(final String id) {
73         final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.INSTANCE_SPAN.getXpath()));
74         final String text = webElement.getText();
75         return text.equalsIgnoreCase(id);
76     }
77
78     /**
79      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
80      */
81     @AllArgsConstructor
82     private enum XpathSelector {
83         ATTRIBUTES_TABLE("attributes-table", "//div[contains(@class,'%s')]"),
84         NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
85         ATTRIBUTES_CHECKBOX("//checkbox[@data-tests-id='%s']"),
86         DECLARE_OUTPUT_BTN("declare-button declare-output", "//button[@data-tests-id='%s']"),
87         INSTANCE_SPAN("//div[contains(@class,'table-rows-header')]"),
88         SET_INPUT_NAME_FIELD("//*[@id=\"myText\"]"),
89         INPUT_NAME_SAVE_BTN("//button[@data-tests-id='Save']"),
90         ADDED_OUTPUT_NOTIFICATION("tab-indication", "//div[@data-tests-id='Outputs']/div[contains(@class, '%s')]");
91
92         @Getter
93         private String id;
94         private final String xpathFormat;
95
96         XpathSelector(final String xpathFormat) {
97             this.xpathFormat = xpathFormat;
98         }
99
100         public String getXpath() {
101             return String.format(xpathFormat, id);
102         }
103
104         public String getXpath(final String... xpathParams) {
105             return String.format(xpathFormat, xpathParams);
106         }
107     }
108 }