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=========================================================
19 package org.onap.sdc.frontend.ci.tests.pages;
21 import lombok.AllArgsConstructor;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.WebDriver;
25 import org.openqa.selenium.WebElement;
28 * Handles the 'Attributes' Tab UI component on 'Attributes & Outputs' Page
30 public class AttributesTabComponent extends AbstractPageObject {
32 public AttributesTabComponent(final WebDriver webDriver) {
37 public void isLoaded() {
38 waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_TABLE.getXpath()));
39 waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()));
42 public void declareOutput(final String attributeName) {
43 if (attributeName == null) {
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();
54 private void waitForAddedOutputNotification() {
55 waitForElementVisibility(By.xpath(XpathSelector.ADDED_OUTPUT_NOTIFICATION.getXpath()));
59 * Checks if a attribute exists.
61 * @return true if exists, false if not
63 public boolean isAttributePresent(final String attributeName) {
65 waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_CHECKBOX.getXpath(attributeName)));
66 } catch (final Exception ignored) {
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);
79 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
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')]");
94 private final String xpathFormat;
96 XpathSelector(final String xpathFormat) {
97 this.xpathFormat = xpathFormat;
100 public String getXpath() {
101 return String.format(xpathFormat, id);
104 public String getXpath(final String... xpathParams) {
105 return String.format(xpathFormat, xpathParams);