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