2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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 static org.junit.jupiter.api.Assertions.assertTrue;
24 import java.util.ArrayList;
25 import java.util.List;
26 import lombok.AllArgsConstructor;
28 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
29 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
30 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
31 import org.openqa.selenium.By;
32 import org.openqa.selenium.WebDriver;
33 import org.openqa.selenium.WebElement;
34 import org.openqa.selenium.support.ui.ExpectedConditions;
37 * Handles the Resource Properties Assignment Page UI actions
39 public class ResourcePropertiesAssignmentPage extends AbstractPageObject {
41 private WebElement wrappingElement;
42 private LoaderHelper loaderHelper;
43 private NotificationComponent notificationComponent;
45 public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
47 notificationComponent = new NotificationComponent(webDriver);
48 loaderHelper = new LoaderHelper(webDriver);
52 public void isLoaded() {
53 wrappingElement = getWait(5)
54 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(XpathSelector.MAIN_DIV.getXpath())));
56 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(XpathSelector.TITLE_DIV.getXpath())));
60 * Gets the software_version property values.
62 * @return the list of software versions found
64 public List<String> getSoftwareVersionProperty() {
65 waitPropertiesToLoad();
66 final By swVersionCheckboxLocator = By.xpath(XpathSelector.SOFTWARE_VERSION_PROPERTY_CHECKBOX.getXpath());
67 waitForElementVisibility(swVersionCheckboxLocator, 5);
69 final List<String> softwareVersionList = new ArrayList<>();
70 final List<WebElement> elements = wrappingElement.findElements(By.xpath(XpathSelector.SOFTWARE_VERSION_INPUT.getXpath()));
71 for (final WebElement element : elements) {
72 softwareVersionList.add(element.getAttribute("value"));
75 return softwareVersionList;
79 * Gets the value of a string TOSCA property.
81 * @return the value of the property
83 public String getStringPropertyValue(final String propertyName) {
84 waitPropertiesToLoad();
85 final By propertyCheckboxLocator = By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName));
86 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
87 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
88 final WebElement propertyInput = propertyRow.findElement(By.xpath(XpathSelector.INPUT_PROPERTY.getXpath(propertyName)));
89 return propertyInput.getAttribute("value");
93 * Set a value to a TOSCA string property.
95 public void setStringPropertyValue(final String propertyName, final String value) {
99 waitPropertiesToLoad();
100 final By propertyCheckboxLocator = By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName));
101 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
102 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
103 final WebElement propertyInput = propertyRow.findElement(By.xpath(XpathSelector.INPUT_PROPERTY.getXpath(propertyName)));
104 propertyInput.sendKeys(value);
107 public void setPropertyValue(final String propertyName, final Object value) {
112 if (value instanceof String) {
113 setStringPropertyValue(propertyName, (String) value);
117 if (value instanceof Integer) {
118 setStringPropertyValue(propertyName, ((Integer) value).toString());
122 if (value instanceof Boolean) {
123 setStringPropertyValue(propertyName, ((Boolean) value).toString());
127 throw new UnsupportedOperationException("Cannot set property value of type: " + value.getClass());
131 * Checks if a property exists.
133 * @return the value of the property
135 public boolean isPropertyPresent(final String propertyName) {
136 waitPropertiesToLoad();
138 waitForElementVisibility(By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName)), 5);
139 } catch (final Exception ignored) {
146 * Waits for the properties loading.
148 private void waitPropertiesToLoad() {
149 waitForElementVisibility(By.xpath(XpathSelector.PROPERTIES_TABLE.getXpath()), 5);
150 waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()), 5);
153 public void saveProperties() {
154 final WebElement saveBtn = waitForElementVisibility(By.xpath(XpathSelector.PROPERTY_SAVE_BTN.getXpath()));
155 assertTrue(saveBtn.isEnabled(), "Property save button should be enabled.");
157 loaderHelper.waitForLoader(20);
158 notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
162 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
165 private enum XpathSelector {
166 MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
167 TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
168 PROPERTIES_TABLE("properties-table", "//div[contains(@class,'%s')]"),
169 NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
170 SOFTWARE_VERSION_PROPERTY_CHECKBOX("software_versions", "//checkbox[@data-tests-id='%s']"),
171 SOFTWARE_VERSION_INPUT("value-prop-software_versions", "//input[starts-with(@data-tests-id,'%s')]"),
172 PROPERTY_CHECKBOX("//checkbox[@data-tests-id='%s']"),
173 PROPERTY_SAVE_BTN("properties-save-button", "//button[@data-tests-id='%s']"),
174 INPUT_PROPERTY("//input[@data-tests-id='value-prop-%s']");
178 private final String xpathFormat;
180 XpathSelector(final String xpathFormat) {
181 this.xpathFormat = xpathFormat;
184 public String getXpath() {
185 return String.format(xpathFormat, id);
188 public String getXpath(final String... xpathParams) {
189 return String.format(xpathFormat, xpathParams);