Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / VlmCreationModal.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * Handles the VLM Creation Modal UI actions
32  */
33 public class VlmCreationModal extends AbstractPageObject {
34
35     private static final Logger LOGGER = LoggerFactory.getLogger(VlmCreationModal.class);
36
37     private WebElement wrappingElement;
38
39     public VlmCreationModal(final WebDriver webDriver) {
40         super(webDriver);
41         timeoutInSeconds = 5;
42     }
43
44     @Override
45     public void isLoaded() {
46         LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_XPATH.getXpath());
47         wrappingElement = waitForElementVisibility(XpathSelector.MODAL_XPATH.getXpath());
48     }
49
50     /**
51      * Fills VLM mandatory entries
52      * @param vendorName  the VLM vendor name
53      * @param description the VLM description
54      */
55     public void fillCreationForm(final String vendorName, final String description) {
56         fillVendorName(vendorName);
57         fillDescription(description);
58     }
59
60     /**
61      * Fills the VLM Vendor Name field
62      * @param vendorName the VLM vendor name
63      */
64     private void fillVendorName(final String vendorName) {
65         setInputValue(XpathSelector.VENDOR_NAME_TXT, vendorName);
66     }
67
68     /**
69      * Fills the VLM description field.
70      *
71      * @param description the VLM description
72      */
73     public void fillDescription(final String description) {
74         setInputValue(XpathSelector.DESCRIPTION_TXT, description);
75     }
76
77     /**
78      * Sets input value to the given Xpath
79      * @param inputTestId the Xpath selected
80      * @param value the value
81      */
82     private void setInputValue(final XpathSelector inputTestId, final String value) {
83         findSubElement(wrappingElement, By.xpath(inputTestId.getXpath())).sendKeys(value);
84     }
85
86     /**
87      * Clicks on the create button.
88      * @return the next page object
89      */
90     public VlmOverviewPage clickOnCreate() {
91         clickElement(XpathSelector.CREATE_BTN);
92         return new VlmOverviewPage(webDriver, new VlmSubmitModal(webDriver));
93     }
94
95     /**
96      * Clicks on the given Xpath element
97      * @param elementTestId the ui element
98      */
99     private void clickElement(final XpathSelector elementTestId) {
100         wrappingElement.findElement(By.xpath(elementTestId.getXpath())).click();
101     }
102
103     /**
104      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
105      */
106     @AllArgsConstructor
107     private enum XpathSelector {
108         MODAL_XPATH("license-model-modal", "//div[@class='%s']"),
109         VENDOR_NAME_TXT("vendor-name", "//*[@data-test-id='%s']"),
110         DESCRIPTION_TXT("vendor-description", "//*[@data-test-id='%s']"),
111         CREATE_BTN("form-submit-button", "//*[@data-test-id='%s']");
112
113         @Getter
114         private final String id;
115         private final String xpathFormat;
116
117         public String getXpath() {
118             return String.format(xpathFormat, id);
119         }
120     }
121
122 }