e06d702afefb88e3833e96323ea3c684e93ab26f
[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         waitForAddedOutputNotification();
49     }
50
51     private void waitForAddedOutputNotification() {
52         waitForElementVisibility(By.xpath(XpathSelector.ADDED_OUTPUT_NOTIFICATION.getXpath()));
53     }
54
55     /**
56      * Checks if a attribute exists.
57      *
58      * @return true if exists, false if not
59      */
60     public boolean isAttributePresent(final String attributeName) {
61         try {
62             waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_CHECKBOX.getXpath(attributeName)));
63         } catch (final Exception ignored) {
64             return false;
65         }
66         return true;
67     }
68
69     public boolean isInstanceSelected(final String id) {
70         final WebElement webElement = waitForElementVisibility(By.xpath(XpathSelector.INSTANCE_SPAN.getXpath()));
71         final String text = webElement.getText();
72         return text.equalsIgnoreCase(id);
73     }
74
75     /**
76      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
77      */
78     @AllArgsConstructor
79     private enum XpathSelector {
80         ATTRIBUTES_TABLE("attributes-table", "//div[contains(@class,'%s')]"),
81         NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
82         ATTRIBUTES_CHECKBOX("//checkbox[@data-tests-id='%s']"),
83         DECLARE_OUTPUT_BTN("declare-button declare-output", "//button[@data-tests-id='%s']"),
84         INSTANCE_SPAN("//div[contains(@class,'table-rows-header')]"),
85         ADDED_OUTPUT_NOTIFICATION("tab-indication", "//div[@data-tests-id='Outputs']/div[contains(@class, '%s')]");
86
87         @Getter
88         private String id;
89         private final String xpathFormat;
90
91         XpathSelector(final String xpathFormat) {
92             this.xpathFormat = xpathFormat;
93         }
94
95         public String getXpath() {
96             return String.format(xpathFormat, id);
97         }
98
99         public String getXpath(final String... xpathParams) {
100             return String.format(xpathFormat, xpathParams);
101         }
102     }
103 }