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.openecomp.sdc.ci.tests.pages;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.WebElement;
25 import org.openqa.selenium.support.ui.Select;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import static org.openecomp.sdc.ci.tests.pages.VspCreationModal.XpathSelector.METHOD_RADIO;
30 import static org.openecomp.sdc.ci.tests.pages.VspCreationModal.XpathSelector.MODAL_XPATH;
33 * Handles the VSP Creation Modal UI actions
35 public class VspCreationModal extends AbstractPageObject {
37 private static final Logger LOGGER = LoggerFactory.getLogger(VspCreationModal.class);
39 private WebElement wrappingElement;
41 public VspCreationModal(final WebDriver webDriver) {
47 public void isLoaded() {
48 LOGGER.debug("Finding element with xpath '{}'", MODAL_XPATH.getXpath());
49 wrappingElement = waitForElementVisibility(MODAL_XPATH.getXpath());
53 * Fills the creation form for the given vsp name.
55 * @param vspName the name of the Vendor Software Product
57 public void fillCreationForm(final String vspName) {
59 selectVendorFirstVendor();
60 selectCategory("resourceNewCategory.network l4+.common network resources");
61 fillDescription(vspName);
62 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 a category in the category list based on the option value.
103 * @param categoryOptionValue the option value
105 public void selectCategory(final String categoryOptionValue) {
106 setSelectValue(XpathSelector.CATEGORY_SELECT, categoryOptionValue);
110 * Selects the network package onboarding procedure option.
112 public void selectNetworkPackageOnboardingProcedure() {
113 wrappingElement.findElement(By.xpath(METHOD_RADIO.getXpath())).click();
116 private void setInputValue(final XpathSelector inputTestId, final String value) {
117 findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
120 private void setSelectIndex(final XpathSelector inputTestId, final int index) {
121 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByIndex(index);
124 private void setSelectValue(final XpathSelector inputTestId, final String value) {
125 new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByValue(value);
128 private void clickElement(final XpathSelector elementTestId) {
129 wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
133 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
135 public enum XpathSelector {
136 MODAL_XPATH("software-product-creation-page", "//div[@class='%s']"),
137 NAME_TXT("new-vsp-name", "//input[@data-test-id='%s']"),
138 VENDOR_SELECT("new-vsp-vendor", "//select[@data-test-id='%s']"),
139 CATEGORY_SELECT("new-vsp-category", "//select[@data-test-id='%s']"),
140 DESCRIPTION_TXT("new-vsp-description", "//textarea[@data-test-id='%s']"),
141 METHOD_RADIO("new-vsp-creation-procedure-heat", "//input[@data-test-id='%s']/parent::label"),
142 CREATE_BTN("form-submit-button", "//*[@data-test-id='%s']");
144 private final String id;
145 private final String xpathFormat;
147 XpathSelector(final String id, final String xpathFormat) {
149 this.xpathFormat = xpathFormat;
152 public String getId() {
156 public String getXpath() {
157 return String.format(xpathFormat, id);