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 / PropertiesAssignmentPage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
24 import com.aventstack.extentreports.Status;
25 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
26 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.PropertiesAssignmentScreen;
27 import org.onap.sdc.frontend.ci.tests.exception.PropertiesAssignmentPageException;
28 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
29 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.Keys;
31 import org.openqa.selenium.NoSuchElementException;
32 import org.openqa.selenium.WebElement;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class PropertiesAssignmentPage {
37
38     private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesAssignmentPage.class);
39
40     private PropertiesAssignmentPage() {
41
42     }
43
44     public static void clickOnInputTab() {
45         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Input Tab");
46         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUTS_TAB.getValue());
47     }
48
49     public static void clickOnPropertiesTab() {
50         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Properties Tab");
51         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.PROPERTIES_TAB.getValue());
52     }
53
54     public static void clickOnCompositionRightTab() {
55         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Composition Right Tab");
56         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.COMPOSITION_TAB.getValue());
57     }
58
59     public static void clickOnPropertyStructureRightTab() {
60         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Property Structure Right Tab");
61         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.PROPERTY_STRUCTURE_TAB.getValue());
62     }
63
64     public static void clickOnDeclareButton() {
65         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Declare Button");
66         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DECLARE_BUTTON.getValue());
67     }
68
69     public static void clickOnSaveButton() {
70         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save Button");
71         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_BUTTON.getValue());
72     }
73
74     public static void clickOnDiscardButton() {
75         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Discard Button");
76         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DISCARD_BUTTON.getValue());
77     }
78
79     public static void clickOnDialogSaveButton() {
80         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save Button in Dialog Popup");
81         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_SAVE.getValue());
82     }
83
84     public static void clickOnDialogDiscardButton() {
85         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Discard Button in Dialog Popup");
86         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_DISCARD.getValue());
87     }
88
89     public static void clickOnDialogCancelButton() {
90         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Cancel Button in Dialog Popup");
91         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.SAVE_DIALOG_CANCEL.getValue());
92     }
93
94     public static void clickOnEditButton(String propertyName) {
95         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Edit button ");
96         GeneralUIUtils.clickOnElementByTestId(PropertyNameBuilder.buildPopupField(propertyName));
97     }
98
99     public static void clickOnSetButton() {
100         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Set button in a property popup ");
101         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_SET_BUTTON.getValue());
102     }
103
104     public static void clickOnExpandButton(String propertyName, int index) {
105         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Expand Complex Property Button");
106         GeneralUIUtils.clickOnElementByTestId(PropertyNameBuilder.buildIExpandButton(propertyName, index));
107     }
108
109     public static void findSearchBoxAndClick(final String resourceName) throws PropertiesAssignmentPageException {
110         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in Properties");
111         try {
112             final WebElement searchTextbox = GeneralUIUtils
113                 .getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());
114             searchTextbox.clear();
115             searchTextbox.sendKeys(resourceName);
116             GeneralUIUtils.ultimateWait();
117         } catch (final Exception e) {
118             final String errorMsg = String.format("Could not interact with search bar, test id '%s'",
119                 PropertiesAssignmentScreen.SEARCH_BOX.getValue());
120             LOGGER.error(errorMsg, e);
121             SetupCDTest.getExtendTest().log(Status.ERROR, errorMsg);
122             throw new PropertiesAssignmentPageException(errorMsg, e);
123         }
124
125         try {
126             SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", resourceName));
127             GeneralUIUtils.clickOnElementByInputTestIdWithoutWait(resourceName);
128             GeneralUIUtils.ultimateWait();
129             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
130         } catch (final Exception e) {
131             final String errorMsg = String.format("Could not click on component named '%s'", resourceName);
132             LOGGER.error(errorMsg, e);
133             SetupCDTest.getExtendTest().log(Status.ERROR, errorMsg);
134             throw new PropertiesAssignmentPageException(errorMsg, e);
135         }
136     }
137
138     private static void clickOnProperty(String propertyName) {
139         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", propertyName));
140         GeneralUIUtils.clickOnElementByTestId(propertyName);
141         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
142     }
143
144     public static void clickOnAddValueToList(String propertyName) throws Exception {
145         try {
146             SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the Add To List button of %s component in Properties", propertyName));
147             GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.ADD_TO_LIST_BUTTON.getValue() + propertyName);
148             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
149         } catch (Exception e) {
150             SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on Add To List button of component named " + propertyName);
151             e.printStackTrace();
152         }
153     }
154
155     public static void clickODeleteValueFromList(String propertyName, int index) throws Exception {
156         try {
157             SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the Delete From List button of %s component in Properties", propertyName));
158             GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.DELETE_FROM_LIST_BUTTON.getValue() + propertyName + "." + index);
159             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
160         } catch (Exception e) {
161             SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on Delete From List button of component named " + propertyName);
162             e.printStackTrace();
163         }
164     }
165
166     public static void clickOnDeleteInputButton() {
167         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Delete Input Button");
168         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUT_DELETE_BUTTON.getValue());
169     }
170
171     public static void clickOnDeleteInputDialogConfirmationButton() {
172         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Delete Input Dialog Confirmation Button");
173         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_DELETE.getValue());
174     }
175
176     public static void clickOnComponentInComposition(final String resourceName) throws Exception {
177         SetupCDTest.getExtendTest()
178             .log(Status.INFO, String.format("Clicking on the %s component on Properties screen", resourceName));
179         try {
180             GeneralUIUtils.clickOnElementByTestId(resourceName);
181         } catch (final Exception e) {
182             SetupCDTest.getExtendTest().log(Status.INFO, "Can't click on component named " + resourceName);
183             throw e;
184         }
185     }
186
187     public static void findInput(String componentName, String resourceName) throws Exception {
188         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + componentName + "_" + resourceName + " on Inputs screen");
189         WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());
190         String searchPattern = componentName + "_" + resourceName;
191
192         searchTextbox.clear();
193         searchTextbox.sendKeys(searchPattern);
194         GeneralUIUtils.ultimateWait();
195     }
196
197     public static void findProperty(String resourceName) throws Exception {
198         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
199         WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.SEARCH_BOX.getValue());
200
201         searchTextbox.clear();
202         searchTextbox.sendKeys(resourceName);
203         GeneralUIUtils.ultimateWait();
204     }
205
206     public static void editPropertyValue(String resourceName, String value) throws Exception {
207         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
208         WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(resourceName);
209
210         clickOnProperty(resourceName);
211         valueTextbox.clear();
212         SetupCDTest.getExtendTest().log(Status.INFO, "Editing " + resourceName + " property on Properties screen");
213         valueTextbox.sendKeys(value);
214         GeneralUIUtils.ultimateWait();
215
216     }
217
218     public static void deletePropertyValue(String resourceName) throws Exception {
219         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property on Properties screen");
220         WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(resourceName);
221
222         clickOnProperty(resourceName);
223         SetupCDTest.getExtendTest().log(Status.INFO, "Deleting " + resourceName + " property on Properties screen");
224         valueTextbox.sendKeys(Keys.chord(Keys.CONTROL, "a"));
225         valueTextbox.sendKeys(Keys.BACK_SPACE);
226         GeneralUIUtils.ultimateWait();
227
228     }
229
230
231     public static Boolean isPropertyChecked(String resourceName) {
232 //              TODO add better implementation for css string
233         GeneralUIUtils.ultimateWait();
234         Boolean isDisabled = GeneralUIUtils.checkForDisabledAttributeInHiddenElement("checkbox[data-tests-id='" + resourceName + "'] input");
235         SetupCDTest.getExtendTest().log(Status.INFO, "Is property checkbox disabled? " + isDisabled);
236         return isDisabled;
237     }
238
239     public static boolean isButtonDisabled(String dataTestId) {
240         return GeneralUIUtils.checkForDisabledAttribute(dataTestId);
241     }
242
243     public static String selectBooleanPropertyValue(String propertyName, String propertyValue) {
244         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + propertyName + " property on Properties screen");
245         String actualPropertyValue = null;
246         try {
247             actualPropertyValue = GeneralUIUtils.getSelectedElementFromDropDown(propertyName).getText();
248         } catch (NoSuchElementException e) {
249             SetupCDTest.getExtendTest().log(Status.INFO, "#selectBooleanPropertyValue - Failed to get selected boolean property value ");
250             SetupCDTest.getExtendTest().log(Status.INFO, e);
251         }
252         try {
253             GeneralUIUtils.getSelectList(propertyValue, propertyName);
254         } catch (NoSuchElementException e) {
255             e.printStackTrace();
256         }
257         return actualPropertyValue;
258     }
259
260
261     //Filter Actions
262     public static void clickOnFilterButton() {
263         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter button ");
264         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_BUTTON.getValue());
265     }
266
267     public static void clickOnFilterAllCheckbox() {
268         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter All Checkbox ");
269         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_ALL.getValue());
270     }
271
272     public static void clickOnFilterCPCheckbox() {
273         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter CP Checkbox ");
274         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_CP.getValue());
275     }
276
277     public static void clickOnFilterVfcCheckbox() {
278         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter VFC Checkbox ");
279         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_VFC.getValue());
280     }
281
282     public static void clickOnFilterVlCheckbox() {
283         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter VL Checkbox ");
284         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CHECKBOX_VL.getValue());
285     }
286
287     public static void clickOnFilterApplyButton() {
288         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Apply Button");
289         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_APPLY_BUTTON.getValue());
290     }
291
292     public static void clickOnFilterCloseButton() {
293         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Close Button");
294         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.FILTER_CLOSE_BUTTON.getValue());
295     }
296
297     public static void clickOnFilterClearAllButton() {
298         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Filter Clear All Button");
299         GeneralUIUtils.clickOnElementByTestId(PropertiesAssignmentScreen.CLEAR_FILTER_BUTTON.getValue());
300     }
301
302     public static void findFilterBoxAndClick(String resourceName) throws Exception {
303         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + resourceName + " property in Properties table");
304         WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesAssignmentScreen.FILTER_BOX.getValue());
305         try {
306             searchTextbox.clear();
307             searchTextbox.sendKeys(resourceName);
308             GeneralUIUtils.ultimateWait();
309         } catch (Exception e) {
310             SetupCDTest.getExtendTest().log(Status.INFO, "Can't interact with search bar");
311             e.printStackTrace();
312         }
313
314     }
315
316
317 }