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 lombok.AllArgsConstructor;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.WebElement;
27 import org.openqa.selenium.support.ui.Select;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Handles the VSP Creation Modal UI actions
34 public class VspCreationModal extends AbstractPageObject {
36 private static final Logger LOGGER = LoggerFactory.getLogger(VspCreationModal.class);
38 private WebElement wrappingElement;
40 public VspCreationModal(final WebDriver webDriver) {
46 public void isLoaded() {
47 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
48 wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
52 * Fills the creation form for the given vsp name.
54 * @param vspName the name of the Vendor Software Product
56 public void fillCreationForm(final String vspName) {
58 selectVendorFirstVendor();
59 selectCategory("resourceNewCategory.network l4+.common network resources");
60 fillDescription(vspName);
61 selectNetworkPackageOnboardingProcedure();
66 * Clicks on the create button.
68 * @return the next page object
70 public SoftwareProductOnboarding clickOnCreate() {
71 clickElement(XpathSelector.CREATE_BTN);
72 return new SoftwareProductOnboarding(webDriver, new VspCommitModal(webDriver));
78 * @param vspName the VSP name
80 public void fillName(final String vspName) {
81 setInputValue(XpathSelector.NAME_TXT, vspName);
85 * Fills the VSP description.
87 * @param description the VSP description
89 public void fillDescription(final String description) {
90 setInputValue(XpathSelector.DESCRIPTION_TXT, description);
94 * Selects the first vendor in the vendor list.
96 public void selectVendorFirstVendor() {
97 setSelectIndex(XpathSelector.VENDOR_SELECT, 1);
101 * Selects the default model.
103 public void selectDefaultModel() {
104 clickElement(XpathSelector.DEFAULT_MODEL_RADIO);
108 * Selects a category in the category list based on the option value.
110 * @param categoryOptionValue the option value
112 public void selectCategory(final String categoryOptionValue) {
113 setSelectValue(XpathSelector.CATEGORY_SELECT, categoryOptionValue);
117 * Selects the network package onboarding procedure option.
119 public void selectNetworkPackageOnboardingProcedure() {
120 wrappingElement.findElement(By.xpath(XpathSelector.ONBOARDING_METHOD_RADIO.getXpath())).click();
123 private void setInputValue(final XpathSelector inputTestId, final String value) {
124 findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
127 private void setSelectIndex(final XpathSelector inputTestId, final int index) {
128 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByIndex(index);
131 private void setSelectValue(final XpathSelector inputTestId, final String value) {
132 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByValue(value);
135 private void clickElement(final XpathSelector elementTestId) {
136 wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
140 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
143 private enum XpathSelector {
144 MODAL_XPATH("software-product-creation-page", "//div[@class='%s']"),
145 NAME_TXT("new-vsp-name", "//input[@data-test-id='%s']"),
146 VENDOR_SELECT("new-vsp-vendor", "//select[@data-test-id='%s']"),
147 CATEGORY_SELECT("new-vsp-category", "//select[@data-test-id='%s']"),
148 DESCRIPTION_TXT("new-vsp-description", "//textarea[@data-test-id='%s']"),
149 ONBOARDING_METHOD_RADIO("new-vsp-creation-procedure-heat", "//input[@data-test-id='%s']/parent::label"),
150 DEFAULT_MODEL_RADIO("model-option-default", "//input[@data-test-id='%s']/parent::label"),
151 CREATE_BTN("form-submit-button", "//*[@data-test-id='%s']");
154 private final String id;
155 private final String xpathFormat;
157 public String getXpath() {
158 return String.format(xpathFormat, id);