Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / 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.openecomp.sdc.ci.tests.pages;
21
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;
28
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;
31
32 /**
33  * Handles the VSP Creation Modal UI actions
34  */
35 public class VspCreationModal extends AbstractPageObject {
36
37     private static final Logger LOGGER = LoggerFactory.getLogger(VspCreationModal.class);
38
39     private WebElement wrappingElement;
40
41     public VspCreationModal(final WebDriver webDriver) {
42         super(webDriver);
43         timeoutInSeconds = 5;
44     }
45
46     @Override
47     public void isLoaded() {
48         LOGGER.debug("Finding element with xpath '{}'", MODAL_XPATH.getXpath());
49         wrappingElement = waitForElementVisibility(MODAL_XPATH.getXpath());
50     }
51
52     /**
53      * Fills the creation form for the given vsp name.
54      *
55      * @param vspName the name of the Vendor Software Product
56      */
57     public void fillCreationForm(final String vspName) {
58         fillName(vspName);
59         selectVendorFirstVendor();
60         selectCategory("resourceNewCategory.network l4+.common network resources");
61         fillDescription(vspName);
62         selectNetworkPackageOnboardingProcedure();
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 a category in the category list based on the option value.
102      *
103      * @param categoryOptionValue the option value
104      */
105     public void selectCategory(final String categoryOptionValue) {
106         setSelectValue(XpathSelector.CATEGORY_SELECT, categoryOptionValue);
107     }
108
109     /**
110      * Selects the network package onboarding procedure option.
111      */
112     public void selectNetworkPackageOnboardingProcedure() {
113         wrappingElement.findElement(By.xpath(METHOD_RADIO.getXpath())).click();
114     }
115
116     private void setInputValue(final XpathSelector inputTestId, final String value) {
117         findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
118     }
119
120     private void setSelectIndex(final XpathSelector inputTestId, final int index) {
121         new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByIndex(index);
122     }
123
124     private void setSelectValue(final XpathSelector inputTestId, final String value) {
125         new Select(findSubElement(wrappingElement, By.xpath(inputTestId.getXpath()))).selectByValue(value);
126     }
127
128     private void clickElement(final XpathSelector elementTestId) {
129         wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
130     }
131
132     /**
133      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
134      */
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']");
143
144         private final String id;
145         private final String xpathFormat;
146
147         XpathSelector(final String id, final String xpathFormat) {
148             this.id = id;
149             this.xpathFormat = xpathFormat;
150         }
151
152         public String getId() {
153             return id;
154         }
155
156         public String getXpath() {
157             return String.format(xpathFormat, id);
158         }
159     }
160
161 }