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 / ResourceCreatePage.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 java.util.List;
23 import lombok.AllArgsConstructor;
24 import lombok.Getter;
25 import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData;
26 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
27 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.Keys;
30 import org.openqa.selenium.WebDriver;
31 import org.openqa.selenium.WebElement;
32 import org.openqa.selenium.support.ui.Select;
33
34 /**
35  * Handles the Resource Create Page UI actions
36  */
37 public class ResourceCreatePage extends ComponentPage {
38
39     private final LoaderHelper loaderHelper;
40     private final NotificationComponent notificationComponent;
41     private final ResourceWorkspaceTopBarComponent topBarComponent;
42     private final ResourceLeftSideMenu resourceLeftSideMenu;
43
44     public ResourceCreatePage(final WebDriver webDriver) {
45         super(webDriver);
46         this.loaderHelper = new LoaderHelper(webDriver);
47         this.notificationComponent = new NotificationComponent(webDriver);
48         this.resourceLeftSideMenu = new ResourceLeftSideMenu(webDriver);
49         this.topBarComponent = new ResourceWorkspaceTopBarComponent(webDriver);
50         timeoutInSeconds = 5;
51     }
52
53     @Override
54     public void isLoaded() {
55         super.isLoaded();
56         waitForElementVisibility(By.xpath(XpathSelector.NAME_INPUT.getXpath()));
57         waitForElementVisibility(By.xpath(XpathSelector.MODEL_SELECT.getXpath()));
58         waitForElementVisibility(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath()));
59         waitForElementVisibility(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()));
60     }
61
62     public void fillForm(final ResourceCreateData resourceCreateData) {
63         fillName(resourceCreateData.getName());
64         setModel(resourceCreateData.getModel());
65         setCategory(resourceCreateData.getCategory());
66         defineTags(resourceCreateData.getTagList());
67         fillDescription(resourceCreateData.getDescription());
68         fillContactId(resourceCreateData.getContactId());
69         fillVendorName(resourceCreateData.getVendorName());
70         fillVendorRelease(resourceCreateData.getVendorRelease());
71         fillVendorModelNumber(resourceCreateData.getVendorModelNumber());
72     }
73
74     private void fillName(final String name) {
75         setInputField(By.xpath(XpathSelector.NAME_INPUT.getXpath()), name);
76     }
77
78     /**
79      * Gets the name field value.
80      *
81      * @return the name field value
82      */
83     public String getName() {
84         return findElement(XpathSelector.NAME_INPUT.getXpath()).getText();
85     }
86
87     private void setModel(final String model) {
88         if (model == null) {
89             return;
90         }
91         setSelectField(By.xpath(XpathSelector.MODEL_SELECT.getXpath()), model);
92     }
93
94     private void setCategory(final String category) {
95         setSelectField(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath()), category);
96     }
97
98     private void defineTags(final List<String> tagList) {
99         final WebElement tagsTextbox = findElement(By.xpath(XpathSelector.TAGS.getXpath()));
100         for (final String tag : tagList) {
101             tagsTextbox.clear();
102             tagsTextbox.sendKeys(tag);
103             tagsTextbox.sendKeys(Keys.ENTER);
104         }
105     }
106
107     private void fillDescription(final String description) {
108         setInputField(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()), description);
109     }
110
111     private void fillContactId(final String contactId) {
112         setInputField(By.xpath(XpathSelector.CONTACT_ID_INPUT.getXpath()), contactId);
113     }
114
115     private void fillVendorName(final String vendorName) {
116         setInputField(By.xpath(XpathSelector.VENDOR_NAME_INPUT.getXpath()), vendorName);
117     }
118
119     private void fillVendorRelease(final String vendorRelease) {
120         setInputField(By.xpath(XpathSelector.VENDOR_RELEASE_INPUT.getXpath()), vendorRelease);
121     }
122
123     private void fillVendorModelNumber(final String vendorModelNumber) {
124         setInputField(By.xpath(XpathSelector.VENDOR_MODEL_NUMBER_INPUT.getXpath()), vendorModelNumber);
125     }
126
127     private void setSelectField(final By locator, final String value) {
128         if (value == null) {
129             return;
130         }
131         new Select(findElement(locator)).selectByVisibleText(value);
132     }
133
134     private void setInputField(final By locator, final String value) {
135         if (value == null) {
136             return;
137         }
138         findElement(locator).sendKeys(value);
139     }
140
141     /**
142      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
143      */
144     @AllArgsConstructor
145     private enum XpathSelector {
146         NAME_INPUT("name", "//input[@data-tests-id='%s']"),
147         MODEL_SELECT("selectModelName", "//select[@data-tests-id='%s']"),
148         CATEGORY_SELECT("selectGeneralCategory", "//select[@data-tests-id='%s']"),
149         TAGS("i-sdc-tag-input", "//input[@data-tests-id='%s']"),
150         DESCRIPTION_TEXT_AREA("description", "//textarea[@data-tests-id='%s']"),
151         CONTACT_ID_INPUT("contactId", "//input[@data-tests-id='%s']"),
152         VENDOR_NAME_INPUT("vendorName", "//input[@data-tests-id='%s']"),
153         VENDOR_RELEASE_INPUT("vendorRelease", "//input[@data-tests-id='%s']"),
154         APPROVE_MESSAGE("checkindialog", "//textarea[@data-tests-id='%s']"),
155         VENDOR_MODEL_NUMBER_INPUT("resourceVendorModelNumber", "//input[@data-tests-id='%s']");
156
157         @Getter
158         private final String id;
159         private final String xpathFormat;
160
161         public String getXpath() {
162             return String.format(xpathFormat, id);
163         }
164     }
165
166 }