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=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages;
22 import lombok.AllArgsConstructor;
24 import org.onap.sdc.frontend.ci.tests.pages.AttributeModal.AttributeData;
25 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
31 * Handles the 'Attributes' Page UI actions
33 public class AttributesPage extends ComponentPage {
35 private WebElement wrappingElement;
37 public AttributesPage(final WebDriver webDriver) {
42 public void isLoaded() {
44 waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()));
45 waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
46 waitForElementVisibility(By.xpath(XpathSelector.ATTRIBUTES_DIV.getXpath()));
47 wrappingElement = findElement(By.xpath(XpathSelector.ATTRIBUTES_DIV.getXpath()));
50 public boolean isAttributePresent(final String attributeName) {
52 final WebElement element = wrappingElement.findElement(By.xpath(XpathSelector.ATTRIBUTES_NAME_SPAN.getXpath(attributeName)));
53 return element != null;
54 } catch (final Exception e) {
59 public void addAttribute(final AttributeData attributeData) {
60 final AttributeModal attributeModal = clickOnAdd();
61 attributeModal.isLoaded();
62 attributeModal.fillForm(attributeData, false);
63 attributeModal.clickSave();
64 loaderHelper.waitForLoader(LoaderHelper.XpathSelector.SDC_LOADER_LARGE, 5);
67 public AttributeModal clickOnAdd() {
68 waitToBeClickable(By.xpath(XpathSelector.ADD_BTN.getXpath())).click();
69 return new AttributeModal(webDriver);
72 public AttributeModal clickOnEdit(final String attributeName) {
73 waitToBeClickable(By.xpath(XpathSelector.EDIT_BTN.getXpath(attributeName))).click();
74 return new AttributeModal(webDriver);
77 public void deleteAttribute(final String attributeName) {
78 if (attributeName == null) {
81 waitForElementVisibility(By.xpath(XpathSelector.DELETE_BTN.getXpath(attributeName))).click();
82 waitToBeClickable(By.xpath(XpathSelector.DELETE_ATTRIBUTE_CONFIRM_BTN.getXpath())).click();
83 waitForElementInvisibility(By.xpath(XpathSelector.DELETE_BTN.getXpath(attributeName)), 5);
86 public void editAttribute(final AttributeData attributeData) {
87 final AttributeModal attributeModal = clickOnEdit(attributeData.getAttributeName());
88 attributeModal.isLoaded();
89 attributeModal.fillForm(attributeData, true);
90 attributeModal.clickSave();
91 loaderHelper.waitForLoader(LoaderHelper.XpathSelector.SDC_LOADER_LARGE, 5);
95 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
98 private enum XpathSelector {
99 MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
100 TITLE_DIV("workspace-tab-title", "//div[contains(@class,'%s') and contains(text(), 'Attributes')]"),
101 ATTRIBUTES_DIV("workspace-attributes", "//div[@class='%s']"),
102 ADD_BTN("svg-icon-label", "//span[contains(@class,'%s') and contains(text(), 'Add')]"),
103 ATTRIBUTES_NAME_SPAN("//div[@data-tests-id='attrib-name_%s']"),
104 EDIT_BTN("//div[contains(@class,'svg-icon') and @data-tests-id='edit_%s']"),
105 DELETE_BTN("//div[contains(@class,'svg-icon') and @data-tests-id='delete_%s']"),
106 DELETE_ATTRIBUTE_CONFIRM_BTN("delete-modal-button-ok", "//button[@data-tests-id='%s']");
110 private final String xpathFormat;
112 XpathSelector(final String xpathFormat) {
113 this.xpathFormat = xpathFormat;
116 public String getXpath(final String... xpathParams) {
117 return String.format(xpathFormat, xpathParams);
120 public String getXpath() {
121 return String.format(xpathFormat, id);