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 static org.junit.jupiter.api.Assertions.assertTrue;
23 import static org.onap.sdc.frontend.ci.tests.pages.PropertyNameBuilder.buildInputField;
25 import com.aventstack.extentreports.Status;
26 import java.util.List;
28 import java.util.stream.Collectors;
29 import lombok.AllArgsConstructor;
31 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
32 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
33 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
34 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
35 import org.openqa.selenium.By;
36 import org.openqa.selenium.WebDriver;
37 import org.openqa.selenium.WebElement;
38 import org.openqa.selenium.support.ui.Select;
41 * Handles the Resource Properties Assignment Input Tab UI actions
43 public class ResourcePropertiesAssignmentInputTab extends AbstractPageObject {
45 private LoaderHelper loaderHelper;
46 private NotificationComponent notificationComponent;
48 public ResourcePropertiesAssignmentInputTab(final WebDriver webDriver) {
50 notificationComponent = new NotificationComponent(webDriver);
51 loaderHelper = new LoaderHelper(webDriver);
55 public void isLoaded() {
56 waitForElementVisibility(XpathSelector.INPUT_TAB.getXpath());
57 isInputPropertiesTableLoaded();
61 * Creates a List of property names from the inputs tab
63 public List<String> getInputPropertyNames() {
64 isInputPropertiesTableLoaded();
65 final List<WebElement> propertyNames = findElements(By.xpath(XpathSelector.INPUT_PROPERTY_NAME.getXpath()));
66 return propertyNames.stream().map(propertyName -> propertyName.getAttribute("innerText")).collect(Collectors.toList());
70 * Adds metadata to a property within the inputs tab based on a property name
72 * @param name used to determine which property to add metadata
73 * @param key the metadata key to add
74 * @param value the metadata value to add
76 public void setInputPropertyMetadata(String name, String key, String value) {
77 isInputPropertiesTableLoaded();
78 findElement(By.xpath(XpathSelector.INPUT_PROPERTY_ADD_METADATA_BUTTON.formatXpath(name))).click();
79 waitForElementVisibility(XpathSelector.INPUT_PROPERTY_METADATA_KEY_VALUE_PAIR.formatXpath(name));
80 List<WebElement> keyValueInputs = findElements(By.xpath(XpathSelector.INPUT_PROPERTY_METADATA_KEY_VALUE_PAIR.formatXpath(name)));
81 keyValueInputs.get(0).sendKeys(key);
82 keyValueInputs.get(1).sendKeys(value);
83 saveInputProperties();
84 ExtentTestActions.takeScreenshot(Status.INFO, name, String.format("Added metadata for property %s", name));
87 private void isInputPropertiesTableLoaded() {
88 waitForElementVisibility(XpathSelector.PROPERTIES_TABLE.getXpath());
89 waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()));
92 public void saveInputProperties() {
93 findElement(By.xpath(XpathSelector.PROPERTY_SAVE_BTN.getXpath())).click();
94 loaderHelper.waitForLoaderInvisibility(20);
95 notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
101 * @param inputsMap the inputs map to be added
103 public void addInputs(final Map<String, String> inputsMap) {
104 isInputPropertiesTableLoaded();
105 inputsMap.forEach((inputName, inputType) -> {
106 WebElement inputAddButton = findElement(By.xpath(XpathSelector.INPUT_ADD_BTN.getXpath()));
107 assertTrue(inputAddButton.isDisplayed());
108 inputAddButton.click();
109 createInput(inputName, inputType);
110 waitForElementInvisibility(By.xpath(XpathSelector.MODAL_BACKGROUND.getXpath()), 5);
111 ExtentTestActions.takeScreenshot(Status.INFO, "added-input",
112 String.format("Input '%s' was created on component", inputName));
117 * Fills the creation input modal.
119 * @param inputName the input name to be created
120 * @param inputType the input type to be selected
122 private void createInput(final String inputName, final String inputType) {
123 final AddPropertyModal addInputModal = new AddPropertyModal(webDriver);
124 addInputModal.isLoaded();
125 addInputModal.fillPropertyForm(inputName, inputType);
126 addInputModal.clickOnCreate();
130 * Verifies if the added input is displayed on the UI.
132 * @param inputsMap the input name to be found
134 public void verifyInputs(final Map<String, String> inputsMap) {
135 for (Map.Entry<String, String> input : inputsMap.entrySet()) {
136 assertTrue(this.getInputPropertyNames().contains(input.getKey()),
137 String.format("%s Input should be listed but found %s", input.getKey(),
138 this.getInputPropertyNames().toString()));
143 * Checks if an input exists.
145 * @param inputName the input name
146 * @return the value of the input
148 public boolean isInputPresent(final String inputName) {
149 isInputPropertiesTableLoaded();
151 waitForElementVisibility(By.xpath(XpathSelector.INPUT_CHECKBOX.formatXpath(inputName)), 5);
152 } catch (final Exception ignored) {
158 public void setInputValue(final String inputName, final Object value) {
163 if (value instanceof String) {
164 setStringInputValue(inputName, (String) value);
168 if (value instanceof Integer) {
169 setStringInputValue(inputName, ((Integer) value).toString());
173 if (value instanceof Boolean) {
174 setBooleanPropertyValue(inputName, ((Boolean) value).toString());
178 throw new UnsupportedOperationException("Cannot set input value of type: " + value.getClass());
181 private void setStringInputValue(final String inputName, final String value) {
182 isInputPropertiesTableLoaded();
183 findElement(By.xpath(XpathSelector.INPUT_VALUE.formatXpath(buildInputField(inputName)))).sendKeys(value);
186 private void setBooleanPropertyValue(final String inputName, final String value) {
187 isInputPropertiesTableLoaded();
188 new Select(findElement(By.xpath(XpathSelector.INPUT_VALUE_BOOLEAN.formatXpath(buildInputField(inputName)))))
189 .selectByVisibleText(value.toUpperCase());
193 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
197 private enum XpathSelector {
198 INPUT_TAB("//*[contains(@data-tests-id, 'Inputs') and contains(@class, 'active')]"),
199 PROPERTIES_TABLE("//div[contains(@class,'properties-table')]"),
200 INPUT_CHECKBOX("//checkbox[@data-tests-id='%s']"),
201 NO_DATA_MESSAGE("//div[contains(@class,'no-data') and text()='No data to display']"),
202 PROPERTY_SAVE_BTN("//button[@data-tests-id='properties-save-button']"),
203 PROPERTY_SAVE_MESSAGE("//div[contains(text(), 'Successfully saved')]"),
204 INPUT_PROPERTY_NAME("//*[contains(@class, 'property-name')]"),
205 INPUT_PROPERTY_TABLE_ROW("//div[contains(@class, 'table-row') and descendant::*[text() = '%s']]"),
206 INPUT_PROPERTY_ADD_METADATA_BUTTON(INPUT_PROPERTY_TABLE_ROW.getXpath().concat("//a")),
207 INPUT_PROPERTY_METADATA_KEY_VALUE_PAIR(INPUT_PROPERTY_TABLE_ROW.getXpath().concat("//input")),
208 INPUT_ADD_BTN("//div[contains(@class,'add-btn')]"),
209 INPUT_VALUE("//input[contains(@class,'value-input') and @data-tests-id='%s']"),
210 INPUT_VALUE_BOOLEAN("//select[@data-tests-id='%s']"),
211 MODAL_BACKGROUND("//div[@class='modal-background']");
214 private final String xpath;
216 public String formatXpath(Object... params) {
217 return String.format(xpath, params);