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;
27 * Handles the 'Outputs' Tab UI component on 'Attributes & Outputs' Page
29 public class OutputsTabComponent extends AbstractPageObject {
31 public OutputsTabComponent(final WebDriver webDriver) {
36 public void isLoaded() {
37 waitForElementVisibility(By.xpath(XpathSelector.OUTPUT_ATTRIBUTES_TABLE.getXpath()));
38 waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()));
41 public void deleteOutput(final String outputName) {
42 if (outputName == null) {
45 waitForElementVisibility(By.xpath(XpathSelector.DELETE_OUTPUT_BTN.getXpath(normalizeOutputName(outputName)))).click();
46 waitToBeClickable(By.xpath(XpathSelector.DELETE_OUTPUT_CONFIRM_BTN.getXpath())).click();
47 waitForElementInvisibility(By.xpath(XpathSelector.OUTPUT_NAME_SPAN.getXpath(normalizeOutputName(outputName))), 5);
51 * Checks if a output exists.
53 * @return true if exists, false if not
55 public boolean isOutputPresent(final String outputName) {
57 waitForElementVisibility(By.xpath(XpathSelector.OUTPUT_NAME_SPAN.getXpath(outputName)));
58 } catch (final Exception ignored) {
65 * Checks if a output deleted.
67 * @return true if deleted, false if not
69 public boolean isOutputDeleted(final String outputName) {
71 findElement(By.xpath(XpathSelector.OUTPUT_NAME_SPAN.getXpath(outputName)));
72 } catch (final Exception ignored) {
78 private String normalizeOutputName(final String outputName) {
79 return outputName.replaceAll(" ", "").replaceAll("-", "").toLowerCase();
83 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
86 private enum XpathSelector {
87 DELETE_OUTPUT_BTN("//span[@data-tests-id='delete-%s']"),
88 OUTPUT_ATTRIBUTES_TABLE("output-attributes-table", "//div[contains(@class,'%s')]"),
89 NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
90 DELETE_OUTPUT_CONFIRM_BTN("Delete", "//button[@data-tests-id='%s']"),
91 OUTPUT_NAME_SPAN("//span[contains(@class,'attribute-name') and contains(text(), '%s')]");
95 private final String xpathFormat;
97 XpathSelector(final String xpathFormat) {
98 this.xpathFormat = xpathFormat;
101 public String getXpath() {
102 return String.format(xpathFormat, id);
105 public String getXpath(final String... xpathParams) {
106 return String.format(xpathFormat, xpathParams);