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.HashMap;
26 import java.util.List;
29 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
30 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
31 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.WebDriver;
34 import org.openqa.selenium.WebElement;
35 import org.openqa.selenium.support.ui.ExpectedConditions;
37 import lombok.AllArgsConstructor;
41 * Handles the Resource Properties Assignment Page UI actions
43 public class ResourcePropertiesAssignmentPage extends AbstractPageObject {
45 private WebElement wrappingElement;
46 private LoaderHelper loaderHelper;
47 private NotificationComponent notificationComponent;
49 public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
51 notificationComponent = new NotificationComponent(webDriver);
52 loaderHelper = new LoaderHelper(webDriver);
56 public void isLoaded() {
57 wrappingElement = getWait(5)
58 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(XpathSelector.MAIN_DIV.getXpath())));
60 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(XpathSelector.TITLE_DIV.getXpath())));
64 * Gets the software_version property values.
66 * @return the list of software versions found
68 public List<String> getSoftwareVersionProperty() {
69 waitPropertiesToLoad();
70 final By swVersionCheckboxLocator = By.xpath(XpathSelector.SOFTWARE_VERSION_PROPERTY_CHECKBOX.getXpath());
71 waitForElementVisibility(swVersionCheckboxLocator, 5);
73 final List<String> softwareVersionList = new ArrayList<>();
74 final List<WebElement> elements = wrappingElement.findElements(By.xpath(XpathSelector.SOFTWARE_VERSION_INPUT.getXpath()));
75 for (final WebElement element : elements) {
76 softwareVersionList.add(element.getAttribute("value"));
79 return softwareVersionList;
83 * Gets the value of a string TOSCA property.
85 * @return the value of the property
87 public String getStringPropertyValue(final String propertyName) {
88 waitPropertiesToLoad();
89 final By propertyCheckboxLocator = By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName));
90 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
91 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
92 final WebElement propertyInput = propertyRow.findElement(By.xpath(XpathSelector.INPUT_PROPERTY.getXpath(propertyName)));
93 return propertyInput.getAttribute("value");
97 * Set a value to a TOSCA string property.
99 public void setStringPropertyValue(final String propertyName, final String value) {
103 waitPropertiesToLoad();
104 final By propertyCheckboxLocator = By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName));
105 final WebElement propertyCheckbox = waitForElementVisibility(propertyCheckboxLocator, 5);
106 final WebElement propertyRow = propertyCheckbox.findElement(By.xpath("./../../.."));
107 final WebElement propertyInput = propertyRow.findElement(By.xpath(XpathSelector.INPUT_PROPERTY.getXpath(propertyName)));
108 propertyInput.sendKeys(value);
111 public void setPropertyValue(final String propertyName, final Object value) {
116 if (value instanceof String) {
117 setStringPropertyValue(propertyName, (String) value);
121 if (value instanceof Integer) {
122 setStringPropertyValue(propertyName, ((Integer) value).toString());
126 if (value instanceof Boolean) {
127 setStringPropertyValue(propertyName, ((Boolean) value).toString());
131 throw new UnsupportedOperationException("Cannot set property value of type: " + value.getClass());
135 * Checks if a property exists.
137 * @return the value of the property
139 public boolean isPropertyPresent(final String propertyName) {
140 waitPropertiesToLoad();
142 waitForElementVisibility(By.xpath(XpathSelector.PROPERTY_CHECKBOX.getXpath(propertyName)), 5);
143 } catch (final Exception ignored) {
150 * Waits for the properties loading.
152 private void waitPropertiesToLoad() {
153 waitForElementVisibility(By.xpath(XpathSelector.PROPERTIES_TABLE.getXpath()), 5);
154 waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()), 5);
157 public void saveProperties() {
158 final WebElement saveBtn = waitForElementVisibility(By.xpath(XpathSelector.PROPERTY_SAVE_BTN.getXpath()));
159 assertTrue(saveBtn.isEnabled(), "Property save button should be enabled.");
161 loaderHelper.waitForLoader(20);
162 notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
166 * Creates a map based on property names and data types
168 public Map<String, String> getPropertyNamesAndTypes() {
169 waitPropertiesToLoad();
170 final Map<String, String> namesAndTypes = new HashMap<String, String>();
171 final List<WebElement> names = findElements(By.xpath(XpathSelector.PROPERTY_NAMES.getXpath()));
172 final List<WebElement> types = findElements(By.xpath(XpathSelector.PROPERTY_TYPES.getXpath()));
174 for (int i = 0;i < names.size();i++) {
175 namesAndTypes.put(names.get(i).getAttribute("innerText"), types.get(i).getAttribute("innerText"));
178 return namesAndTypes;
182 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
185 private enum XpathSelector {
186 MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
187 TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
188 PROPERTIES_TABLE("properties-table", "//div[contains(@class,'%s')]"),
189 NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
190 SOFTWARE_VERSION_PROPERTY_CHECKBOX("software_versions", "//checkbox[@data-tests-id='%s']"),
191 SOFTWARE_VERSION_INPUT("value-prop-software_versions", "//input[starts-with(@data-tests-id,'%s')]"),
192 PROPERTY_CHECKBOX("//checkbox[@data-tests-id='%s']"),
193 PROPERTY_SAVE_BTN("properties-save-button", "//button[@data-tests-id='%s']"),
194 INPUT_PROPERTY("//input[@data-tests-id='value-prop-%s']"),
195 PROPERTY_TYPES("//*[contains(@data-tests-id, 'propertyType')]"),
196 PROPERTY_NAMES("//*[contains(@data-tests-id, 'propertyName')]");
200 private final String xpathFormat;
202 XpathSelector(final String xpathFormat) {
203 this.xpathFormat = xpathFormat;
206 public String getXpath() {
207 return String.format(xpathFormat, id);
210 public String getXpath(final String... xpathParams) {
211 return String.format(xpathFormat, xpathParams);