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;
23 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.INPUT_PROPERTY;
24 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.MAIN_DIV;
25 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.NO_DATA_MESSAGE;
26 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.PROPERTIES_TABLE;
27 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.PROPERTY_CHECKBOX;
28 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.PROPERTY_SAVE_BTN;
29 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.SOFTWARE_VERSION_INPUT;
30 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.SOFTWARE_VERSION_PROPERTY_CHECKBOX;
31 import static org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.TITLE_DIV;
33 import java.util.ArrayList;
34 import java.util.List;
35 import lombok.AllArgsConstructor;
37 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
38 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
39 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
40 import org.openqa.selenium.By;
41 import org.openqa.selenium.WebDriver;
42 import org.openqa.selenium.WebElement;
43 import org.openqa.selenium.support.ui.ExpectedConditions;
46 * Handles the Resource Properties Assignment Page UI actions
48 public class ResourcePropertiesAssignmentPage extends AbstractPageObject {
50 private WebElement wrappingElement;
51 private LoaderHelper loaderHelper;
52 private NotificationComponent notificationComponent;
54 public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
56 notificationComponent = new NotificationComponent(webDriver);
57 loaderHelper = new LoaderHelper(webDriver);
61 public void isLoaded() {
62 wrappingElement = getWait(5)
63 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(MAIN_DIV.getXpath())));
65 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(TITLE_DIV.getXpath())));
69 * Gets the software_version property values.
71 * @return the list of software versions found
73 public List<String> getSoftwareVersionProperty() {
74 waitPropertiesToLoad();
75 final By swVersionCheckboxLocator = By.xpath(SOFTWARE_VERSION_PROPERTY_CHECKBOX.getXpath());
76 waitForElementVisibility(swVersionCheckboxLocator, 5);
78 final List<String> softwareVersionList = new ArrayList<>();
79 final List<WebElement> elements = wrappingElement.findElements(By.xpath(SOFTWARE_VERSION_INPUT.getXpath()));
80 for (final WebElement element : elements) {
81 softwareVersionList.add(element.getAttribute("value"));
84 return softwareVersionList;
88 * Gets the value of a string TOSCA property.
90 * @return the value of the property
92 public String getStringPropertyValue(final String propertyName) {
93 waitPropertiesToLoad();
94 final By propertyCheckboxLocator = By.xpath(PROPERTY_CHECKBOX.getXpath(propertyName));
95 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
96 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
97 final WebElement propertyInput = propertyRow.findElement(By.xpath(INPUT_PROPERTY.getXpath(propertyName)));
98 return propertyInput.getAttribute("value");
102 * Set a value to a TOSCA string property.
104 public void setStringPropertyValue(final String propertyName, final String value) {
108 waitPropertiesToLoad();
109 final By propertyCheckboxLocator = By.xpath(PROPERTY_CHECKBOX.getXpath(propertyName));
110 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
111 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
112 final WebElement propertyInput = propertyRow.findElement(By.xpath(INPUT_PROPERTY.getXpath(propertyName)));
113 propertyInput.sendKeys(value);
116 public void setPropertyValue(final String propertyName, final Object value) {
121 if (value instanceof String) {
122 setStringPropertyValue(propertyName, (String) value);
126 if (value instanceof Integer) {
127 setStringPropertyValue(propertyName, ((Integer) value).toString());
131 if (value instanceof Boolean) {
132 setStringPropertyValue(propertyName, ((Boolean) value).toString());
136 throw new UnsupportedOperationException("Cannot set property value of type: " + value.getClass());
140 * Checks if a property exists.
142 * @return the value of the property
144 public boolean isPropertyPresent(final String propertyName) {
145 waitPropertiesToLoad();
147 waitForElementVisibility(By.xpath(PROPERTY_CHECKBOX.getXpath(propertyName)), 5);
148 } catch (final Exception ignored) {
155 * Waits for the properties loading.
157 private void waitPropertiesToLoad() {
158 waitForElementVisibility(By.xpath(PROPERTIES_TABLE.getXpath()), 5);
159 waitForElementInvisibility(By.xpath(NO_DATA_MESSAGE.getXpath()), 5);
162 public void saveProperties() {
163 final WebElement saveBtn = waitForElementVisibility(By.xpath(PROPERTY_SAVE_BTN.getXpath()));
164 assertTrue(saveBtn.isEnabled(), "Property save button should be enabled.");
166 loaderHelper.waitForLoader(20);
167 notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
171 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
174 public enum XpathSelector {
175 MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
176 TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
177 PROPERTIES_TABLE("properties-table", "//div[contains(@class,'%s')]"),
178 NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
179 SOFTWARE_VERSION_PROPERTY_CHECKBOX("software_versions", "//checkbox[@data-tests-id='%s']"),
180 SOFTWARE_VERSION_INPUT("value-prop-software_versions", "//input[starts-with(@data-tests-id,'%s')]"),
181 PROPERTY_CHECKBOX("//checkbox[@data-tests-id='%s']"),
182 PROPERTY_SAVE_BTN("properties-save-button", "//button[@data-tests-id='%s']"),
183 INPUT_PROPERTY("//input[@data-tests-id='value-prop-%s']");
187 private final String xpathFormat;
189 XpathSelector(final String xpathFormat) {
190 this.xpathFormat = xpathFormat;
193 public String getXpath() {
194 return String.format(xpathFormat, id);
197 public String getXpath(final String... xpathParams) {
198 return String.format(xpathFormat, xpathParams);