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.onap.sdc.frontend.ci.tests.datatypes.CategorySelect;
25 import org.onap.sdc.frontend.ci.tests.datatypes.VspCreateData;
26 import org.onap.sdc.frontend.ci.tests.datatypes.VspOnboardingProcedure;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.Keys;
29 import org.openqa.selenium.WebDriver;
30 import org.openqa.selenium.WebElement;
31 import org.openqa.selenium.support.ui.Select;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Handles the VSP Creation Modal UI actions
38 public class VspCreationModal extends AbstractPageObject {
40 private static final Logger LOGGER = LoggerFactory.getLogger(VspCreationModal.class);
42 private WebElement wrappingElement;
44 public VspCreationModal(final WebDriver webDriver) {
50 public void isLoaded() {
51 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
52 wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
56 * Fills the creation form with the given data.
58 * @param vspCreateData the data to fill the Vendor Software Product create form
60 public void fillCreationForm(final VspCreateData vspCreateData) {
61 fillName(vspCreateData.getName());
62 selectVendorOrElseAny(vspCreateData.getVendor());
63 selectCategory(vspCreateData.getCategory());
64 fillDescription(vspCreateData.getDescription());
65 selectOnboardingProcedure(vspCreateData.getOnboardingProcedure());
66 selectModel(vspCreateData.getModel());
70 * Clicks on the create button.
72 * @return the next page object
74 public SoftwareProductOnboarding clickOnCreate() {
75 clickElement(XpathSelector.CREATE_BTN);
76 return new SoftwareProductOnboarding(webDriver, new VspCommitModal(webDriver));
82 * @param vspName the VSP name
84 public void fillName(final String vspName) {
85 setInputValue(XpathSelector.NAME_TXT, vspName);
89 * Fills the VSP description.
91 * @param description the VSP description
93 public void fillDescription(final String description) {
94 setInputValue(XpathSelector.DESCRIPTION_TXT, description);
98 * Selects the given vendor option. If a null value is given, selects the first option available.
100 * @param vendor the vendor option to select
102 public void selectVendorOrElseAny(final String vendor) {
103 if (vendor == null) {
104 selectVendorFirstVendor();
107 setSelectValue(XpathSelector.VENDOR_SELECT, vendor);
111 * Selects the first vendor in the vendor list.
113 public void selectVendorFirstVendor() {
114 setSelectIndex(XpathSelector.VENDOR_SELECT, 1);
118 * Selects the default model.
120 public void selectDefaultModel() {
121 clickElement(XpathSelector.DEFAULT_MODEL_RADIO);
124 public void selectModel(final String model) {
126 selectDefaultModel();
129 clickElement(XpathSelector.OTHER_MODEL_RADIO);
130 final WebElement modelSelect = findSubElement(wrappingElement, XpathSelector.MODEL_SELECT.getXpath());
131 modelSelect.sendKeys(model);
132 modelSelect.sendKeys(Keys.ENTER);
136 * Selects a category in the category list based on the option value.
138 * @param categoryOptionValue the option value
140 public void selectCategory(final CategorySelect categoryOptionValue) {
141 setSelectValue(XpathSelector.CATEGORY_SELECT, categoryOptionValue.getOption());
145 * Selects the network package onboarding procedure option.
147 * @param vspOnboardingProcedure the onboarding procedure to select
149 public void selectOnboardingProcedure(final VspOnboardingProcedure vspOnboardingProcedure) {
150 if (VspOnboardingProcedure.MANUAL == vspOnboardingProcedure) {
151 wrappingElement.findElement(By.xpath(XpathSelector.ONBOARDING_MANUAL_PROCEDURE_RADIO.getXpath())).click();
154 if (VspOnboardingProcedure.NETWORK_PACKAGE == vspOnboardingProcedure) {
155 wrappingElement.findElement(By.xpath(XpathSelector.ONBOARDING_PACKAGE_PROCEDURE_RADIO.getXpath())).click();
158 throw new UnsupportedOperationException(String.format("Onboarding procedure option '%s' not yet supported", vspOnboardingProcedure));
161 private void setInputValue(final XpathSelector inputTestId, final String value) {
162 findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
165 private void setSelectIndex(final XpathSelector inputTestId, final int index) {
166 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByIndex(index);
169 private void setSelectValue(final XpathSelector inputTestId, final String value) {
170 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByValue(value);
173 private void clickElement(final XpathSelector elementTestId) {
174 wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
178 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
181 private enum XpathSelector {
182 MODAL_XPATH("software-product-creation-page", "//div[@class='%s']"),
183 NAME_TXT("new-vsp-name", "//input[@data-test-id='%s']"),
184 VENDOR_SELECT("new-vsp-vendor", "//select[@data-test-id='%s']"),
185 CATEGORY_SELECT("new-vsp-category", "//select[@data-test-id='%s']"),
186 DESCRIPTION_TXT("new-vsp-description", "//textarea[@data-test-id='%s']"),
187 ONBOARDING_PACKAGE_PROCEDURE_RADIO("new-vsp-creation-procedure-heat", "//input[@data-test-id='%s']/parent::label"),
188 ONBOARDING_MANUAL_PROCEDURE_RADIO("new-vsp-creation-procedure-manual", "//input[@data-test-id='%s']/parent::label"),
189 DEFAULT_MODEL_RADIO("model-option-default", "//input[@data-test-id='%s']/parent::label"),
190 OTHER_MODEL_RADIO("model-option-other", "//input[@data-test-id='%s']/parent::label"),
191 MODEL_SELECT("model-option-select", "//div[@data-test-id='%s']//input"),
192 CREATE_BTN("form-submit-button", "//*[@data-test-id='%s']");
195 private final String id;
196 private final String xpathFormat;
198 public String getXpath() {
199 return String.format(xpathFormat, id);