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 / ResourceGeneralPage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.frontend.ci.tests.pages;
22
23 import org.onap.sdc.backend.ci.tests.datatypes.ComponentReqDetails;
24 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
25 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
26 import org.openqa.selenium.Keys;
27 import org.openqa.selenium.WebElement;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33 public class ResourceGeneralPage extends GeneralPageElements {
34
35     private static final int SLEEP_DURATION = 500;
36
37     protected ResourceGeneralPage() {
38         super();
39     }
40
41     public static WebElement getNameField() {
42         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ResourceMetadataEnum.RESOURCE_NAME.getValue());
43     }
44
45     public static WebElement getDescriptionField() {
46         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.DESCRIPTION.getValue());
47     }
48
49     public static String getModelDataTestsIdAttribute() {
50         return DataTestIdEnum.ResourceMetadataEnum.MODEL.getValue();
51     }
52
53     public static String getCategoryDataTestsIdAttribute() {
54         return DataTestIdEnum.ResourceMetadataEnum.CATEGORY.getValue();
55     }
56
57     public static WebElement getVendorNameField() {
58         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ResourceMetadataEnum.VENDOR_NAME.getValue());
59     }
60
61     public static WebElement getVendorReleaseField() {
62         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ResourceMetadataEnum.VENDOR_RELEASE.getValue());
63     }
64
65     public static WebElement getTagsField() {
66         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ResourceMetadataEnum.TAGS.getValue());
67     }
68
69     public static WebElement getContactIdField() {
70         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ResourceMetadataEnum.CONTACT_ID.getValue());
71     }
72
73     /***************************************************************/
74
75     public static String getNameText() {
76         return getNameField().getAttribute("value");
77     }
78
79     public static void defineName(String resourceName) {
80         WebElement resourceNameTextbox = getNameField();
81         resourceNameTextbox.clear();
82         resourceNameTextbox.sendKeys(resourceName);
83     }
84
85     public static void defineNameWithPaste() {
86         defineTextBoxWithPaste(getNameField());
87     }
88
89     public static String getDescriptionText() {
90         return getDescriptionField().getAttribute("value");
91     }
92
93     public static void defineDescription(String description) {
94         WebElement descriptionTextbox = getDescriptionField();
95         descriptionTextbox.clear();
96         descriptionTextbox.sendKeys(description);
97     }
98
99     public static void defineDescriptionWithPaste() {
100         defineTextBoxWithPaste(getDescriptionField());
101     }
102
103     public static String getVendorNameText() {
104         return getVendorNameField().getAttribute("value");
105     }
106
107     public static void defineVendorName(String vendorName) {
108         WebElement vendorNameTextbox = getVendorNameField();
109         vendorNameTextbox.clear();
110         vendorNameTextbox.sendKeys(vendorName);
111     }
112
113     public static void defineVendorNameWithPaste() {
114         defineTextBoxWithPaste(getVendorNameField());
115     }
116
117     public static String getVendorReleaseText() {
118         return getVendorReleaseField().getAttribute("value");
119     }
120
121     public static void defineVendorRelease(String vendorRelease) {
122         WebElement vendorReleaseTextbox = getVendorReleaseField();
123         vendorReleaseTextbox.clear();
124         vendorReleaseTextbox.sendKeys(vendorRelease);
125     }
126
127     public static void defineVendorReleaseWithPaste() {
128         defineTextBoxWithPaste(getVendorReleaseField());
129     }
130
131     public static void defineTag(String resourceTags) {
132         WebElement tagTextbox = getTagsField();
133         tagTextbox.clear();
134         tagTextbox.sendKeys(resourceTags);
135         tagTextbox.sendKeys(Keys.ENTER);
136     }
137
138     public static void defineTagsList(ComponentReqDetails component, String[] tags) {
139         List<String> taglist = new ArrayList<String>();
140         WebElement resourceTagsTextbox = getTagsField();
141         for (String tag : tags) {
142             resourceTagsTextbox.clear();
143             resourceTagsTextbox.sendKeys(tag);
144             GeneralUIUtils.sleep(SLEEP_DURATION);
145             resourceTagsTextbox.sendKeys(Keys.ENTER);
146             taglist.add(tag);
147         }
148         component.getTags().addAll(taglist);
149     }
150
151     public static void defineTagsListWithPaste() {
152         List<String> taglist = new ArrayList<String>();
153         WebElement resourceTagsTextbox = getTagsField();
154         defineTextBoxWithPaste(resourceTagsTextbox);
155         resourceTagsTextbox.sendKeys(Keys.ENTER);
156     }
157
158     public static void defineCategory(String category) {
159         GeneralUIUtils.getSelectList(category, getCategoryDataTestsIdAttribute());
160     }
161
162     public static String getContactIdText() {
163         return getContactIdField().getAttribute("value");
164     }
165
166     public static void defineContactId(String userId) {
167         WebElement contactIdTextbox = getContactIdField();
168         contactIdTextbox.clear();
169         contactIdTextbox.sendKeys(userId);
170         GeneralUIUtils.waitForLoader();
171     }
172
173     public static List<WebElement> getElementsFromTagsTable() {
174         return GeneralUIUtils.getWebElementsListByTestID(DataTestIdEnum.ResourceMetadataEnum.TAGS_TABLE.getValue());
175     }
176
177     public static void defineTextBoxWithPaste(WebElement textBox) {
178         textBox.clear();
179         textBox.sendKeys(Keys.CONTROL + "v");
180         GeneralUIUtils.ultimateWait();
181     }
182
183     public static void moveToToscaArtifactsSectionAndDownloadTosca() {
184         getLeftMenu().moveToToscaArtifactsScreen();
185         ToscaArtifactsPage.downloadCsar();
186     }
187
188     public static String getVersionUI() {
189         String actualVersion = GeneralUIUtils.getSelectedElementFromDropDown(DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue()).getText().replace("V", "");
190         return actualVersion;
191     }
192 }