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 waitForAddedOutputNotification();
51 private void waitForAddedOutputNotification() {
52 waitForElementVisibility(By.xpath(XpathSelector.ADDED_OUTPUT_NOTIFICATION.getXpath()));
56 * Checks if a attribute exists.
58 * @return true if exists, false if not
60 public boolean isAttributePresent(final String attributeName) {
62 waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_CHECKBOX.getXpath(attributeName)));
63 } catch (final Exception ignored) {
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);
76 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
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')]");
89 private final String xpathFormat;
91 XpathSelector(final String xpathFormat) {
92 this.xpathFormat = xpathFormat;
95 public String getXpath() {
96 return String.format(xpathFormat, id);
99 public String getXpath(final String... xpathParams) {
100 return String.format(xpathFormat, xpathParams);