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 com.google.common.collect.ImmutableSet;
23 import lombok.AllArgsConstructor;
25 import org.openqa.selenium.By;
26 import org.openqa.selenium.WebDriver;
27 import org.openqa.selenium.WebElement;
28 import org.openqa.selenium.support.ui.Select;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Handles the Property Creation Modal UI actions
35 public class AddPropertyModal extends AbstractPageObject {
37 private static final Logger LOGGER = LoggerFactory.getLogger(AddPropertyModal.class);
39 private WebElement wrappingElement;
41 public AddPropertyModal(final WebDriver webDriver) {
47 public void isLoaded() {
48 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
49 wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
53 * Fills the property modal creation.
54 * @param propertyName the property name to be created
55 * @param propertyType the property type to be selected
57 public void fillPropertyForm(final String propertyName, final String propertyType) {
58 fillName(propertyName);
59 selectType(propertyType);
60 if (isComplexType(propertyType)) {
63 fillDescription("Integration Test for adding property to a component");
67 * Clicks on the create button.
69 public void clickOnCreate() {
70 clickElement(XpathSelector.SAVE_BTN);
74 * Fills the Property name.
76 * @param propertyName the property name
78 private void fillName(final String propertyName) {
79 setInputValue(XpathSelector.NAME_TXT, propertyName);
83 * Selects a property type based on the option value
85 * @param propertyType the option value
87 private void selectType(final String propertyType) {
88 setSelectValue(propertyType);
92 * Fills the property creation description.
94 * @param description the property description
96 private void fillDescription(final String description) {
97 setInputValue(XpathSelector.DESCRIPTION_TXT, description);
102 * @param inputTestId Data test id Xpath
103 * @param value Input value
105 private void setInputValue(final XpathSelector inputTestId, final String value) {
106 findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
110 * Selects the option from the given propertyType value
111 * @param propertyType option value to be selected
113 private void setSelectValue(final String propertyType) {
114 new Select(findElement(By.xpath(XpathSelector.PROPERTY_TYPE_SELECT.getXpath()))).selectByVisibleText(propertyType);
118 * Sets Schema Type for complex types
120 private void setSchemaType() {
121 new Select(findElement(By.xpath(XpathSelector.PROPERTY_SCHEMA_TYPE_SELECT.getXpath()))).selectByVisibleText("string");
124 private void clickElement(final XpathSelector elementTestId) {
125 wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
129 * Verifies if the given property type is a complex type
130 * @param propertyType Property type
131 * @return true if property type is found
133 private boolean isComplexType(final String propertyType) {
134 return ImmutableSet.of("map", "list").contains(propertyType);
138 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
141 private enum XpathSelector {
142 MODAL_XPATH("custom-modal", "//div[contains(@class,'%s')]"),
143 NAME_TXT("property-name", "//input[@data-tests-id='%s']"),
144 PROPERTY_TYPE_SELECT("value-property-type", "//select[@data-tests-id='%s']"),
145 PROPERTY_SCHEMA_TYPE_SELECT("value-property-schema-type", "//select[@data-tests-id='%s']"),
146 PROPERTY_CHECKBOX("//checkbox[@data-tests-id='%s']"),
147 DESCRIPTION_TXT("property-description", "//textarea[@data-tests-id='%s']"),
148 SAVE_BTN("Save", "//*[@data-tests-id='%s']");
152 private final String xpathFormat;
154 XpathSelector(final String xpathFormat) {
155 this.xpathFormat = xpathFormat;
158 public String getXpath() {
159 return String.format(xpathFormat, id);
162 public String getXpath(final String... xpathParams) {
163 return String.format(xpathFormat, xpathParams);