Specify a model while creating a VSP
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / VspCreationModal.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages;
21
22 import lombok.AllArgsConstructor;
23 import lombok.Getter;
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;
30
31 /**
32  * Handles the VSP Creation Modal UI actions
33  */
34 public class VspCreationModal extends AbstractPageObject {
35
36     private static final Logger LOGGER = LoggerFactory.getLogger(VspCreationModal.class);
37
38     private WebElement wrappingElement;
39
40     public VspCreationModal(final WebDriver webDriver) {
41         super(webDriver);
42         timeoutInSeconds = 5;
43     }
44
45     @Override
46     public void isLoaded() {
47         LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
48         wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
49     }
50
51     /**
52      * Fills the creation form for the given vsp name.
53      *
54      * @param vspName the name of the Vendor Software Product
55      */
56     public void fillCreationForm(final String vspName) {
57         fillName(vspName);
58         selectVendorFirstVendor();
59         selectCategory("resourceNewCategory.network l4+.common network resources");
60         fillDescription(vspName);
61         selectNetworkPackageOnboardingProcedure();
62         selectDefaultModel();
63     }
64
65     /**
66      * Clicks on the create button.
67      *
68      * @return the next page object
69      */
70     public SoftwareProductOnboarding clickOnCreate() {
71         clickElement(XpathSelector.CREATE_BTN);
72         return new SoftwareProductOnboarding(webDriver, new VspCommitModal(webDriver));
73     }
74
75     /**
76      * Fills the VSP name.
77      *
78      * @param vspName the VSP name
79      */
80     public void fillName(final String vspName) {
81         setInputValue(XpathSelector.NAME_TXT, vspName);
82     }
83
84     /**
85      * Fills the VSP description.
86      *
87      * @param description the VSP description
88      */
89     public void fillDescription(final String description) {
90         setInputValue(XpathSelector.DESCRIPTION_TXT, description);
91     }
92
93     /**
94      * Selects the first vendor in the vendor list.
95      */
96     public void selectVendorFirstVendor() {
97         setSelectIndex(XpathSelector.VENDOR_SELECT, 1);
98     }
99
100     /**
101      * Selects the default model.
102      */
103     public void selectDefaultModel() {
104         clickElement(XpathSelector.DEFAULT_MODEL_RADIO);
105     }
106
107     /**
108      * Selects a category in the category list based on the option value.
109      *
110      * @param categoryOptionValue the option value
111      */
112     public void selectCategory(final String categoryOptionValue) {
113         setSelectValue(XpathSelector.CATEGORY_SELECT, categoryOptionValue);
114     }
115
116     /**
117      * Selects the network package onboarding procedure option.
118      */
119     public void selectNetworkPackageOnboardingProcedure() {
120         wrappingElement.findElement(By.xpath(XpathSelector.ONBOARDING_METHOD_RADIO.getXpath())).click();
121     }
122
123     private void setInputValue(final XpathSelector inputTestId, final String value) {
124         findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
125     }
126
127     private void setSelectIndex(final XpathSelector inputTestId, final int index) {
128         new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByIndex(index);
129     }
130
131     private void setSelectValue(final XpathSelector inputTestId, final String value) {
132         new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByValue(value);
133     }
134
135     private void clickElement(final XpathSelector elementTestId) {
136         wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
137     }
138
139     /**
140      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
141      */
142     @AllArgsConstructor
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']");
152
153         @Getter
154         private final String id;
155         private final String xpathFormat;
156
157         public String getXpath() {
158             return String.format(xpathFormat, id);
159         }
160     }
161
162 }