[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / InputsPage.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.openecomp.sdc.ci.tests.pages;
22
23 import java.util.List;
24 import java.util.stream.Collectors;
25
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.InputsScreenService;
28 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
29 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebElement;
32 import org.testng.TestException;
33
34 import com.aventstack.extentreports.Status;
35
36 public class InputsPage extends GeneralPageElements {
37
38         public InputsPage() {
39                 super();
40                 
41         }
42
43         public static List<WebElement> getInstancePropertiesList(String instanceName) {
44                 List<WebElement> propertyRows = null;
45                 GeneralUIUtils.clickOnElementByText(instanceName);
46                 GeneralUIUtils.ultimateWait();
47                 propertyRows = getVisibleProperites();
48                 return propertyRows;
49         }
50
51         public static List<WebElement> getVisibleProperites() {
52                 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='vf-instance-list']"));
53                 for (WebElement instance : instancesFromTable){
54                         Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
55                         if (!parentAttributes.toString().contains("hidden")){
56                                 return instance.findElements(By.className("property-row"));
57                         }
58                 }
59                 return null;
60         }
61         
62         public static void addInputToService(String VFInstanceName, String propertyName) throws Exception{
63                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding property %s from VF instance %s to Service", propertyName, VFInstanceName));
64                 List<WebElement> instaceInputs = getInstanceInputsList(VFInstanceName);
65                 for(WebElement instancInput: instaceInputs){
66                         String actualPropertyName = instancInput.findElement(By.className("title-text")).getText();
67                         if (actualPropertyName.equals(propertyName) && clickOnVFInputCheckbox(instancInput)){
68                                 clickOnAddInputButton();
69                         }
70                 }
71         }
72
73     public static List<WebElement> getInstanceInputsList(String instanceName) {
74                 List<WebElement> inputRows = null;
75                 GeneralUIUtils.clickOnElementByText(instanceName);
76                 GeneralUIUtils.ultimateWait();
77                 inputRows = getVisibleInputs(inputRows);
78                 return inputRows;
79     }
80     
81         public static List<WebElement> getVisibleInputs(List<WebElement> inputRows) {
82                 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='vf-instance-list']"));
83                 for (WebElement instance : instancesFromTable){
84                         Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
85                         if (!parentAttributes.toString().contains("hidden")){
86                                 inputRows = instance.findElements(By.className("input-row"));
87                                 break;
88                         }
89                 }
90                 return inputRows;
91         }
92         
93         public static void clickOnAddInputButton(){
94                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Add Input aka Greater than symbol button"));
95                 GeneralUIUtils.clickOnElementByTestId(InputsScreenService.ADD_SELECTED_INPUTS_BTN.getValue());
96                 GeneralUIUtils.ultimateWait();          
97         }
98         
99         public static boolean clickOnVFInputCheckbox(WebElement instancInput){
100                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on VF instance input checkbox"));
101                 instancInput.findElement(By.className("tlv-checkbox-label")).click();
102                 GeneralUIUtils.ultimateWait();
103                 return instancInput.findElement(By.className("tlv-checkbox-i")).getAttribute("class").contains("ng-not-empty");
104         }
105         
106         public static WebElement getServiceInput(String VFInstanceName, String propertyName) throws Exception{
107                 String expectedInputName = String.format("%s_%s", VFInstanceName.replace(" ", "").toLowerCase(), propertyName);
108                 List<WebElement> inputsFromTable = GeneralUIUtils.getElementsByCSS(InputsScreenService.SERVICE_INPUT_ROW.getValue());
109             for(WebElement inputFromTable: inputsFromTable){
110                 String actualInputName = inputFromTable.findElement(By.className("title-text")).getText();
111                 if(actualInputName.equals(expectedInputName)){
112                         return inputFromTable;
113                 }
114             }
115             throw new TestException(String.format("%s input don't exist", expectedInputName));
116         }
117             
118         public static void deleteServiceInput(String VFInstanceName, String propertyName) throws Exception{
119                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting property %s in VF instance %s ", propertyName, VFInstanceName));
120                 WebElement serviceInput = getServiceInput(VFInstanceName, propertyName);
121                 serviceInput.findElement(By.cssSelector(InputsScreenService.DELETE_INPUT_BTN.getValue())).click();
122                 GeneralUIUtils.ultimateWait();
123                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on OK button "));
124                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.OK.getValue());
125                 GeneralUIUtils.ultimateWait();          
126         }
127         
128         public static List<String> getVFCInstancesNamesFromTable() throws Exception{
129                 WebElement inputsTable = getInputsTable("VFC ");
130             return       inputsTable.findElements(By.cssSelector("span[class^='title-text']")).stream().
131                              map(e -> e.getText()).
132                              collect(Collectors.toList());
133         }
134         
135         public static WebElement getInputsTable(String tableName) throws Exception{
136                  List<WebElement> tableElements = GeneralUIUtils.getElementsByCSS("div.table");
137                  for(WebElement tableElement: tableElements){
138                          String tableTitle = GeneralUIUtils.getElementfromElementByCSS(tableElement, "div.table-header").getText();
139                          if (tableTitle.contains(tableName)){
140                                  return tableElement;
141                          }
142                  }
143                  throw new TestException(String.format("Can't find %s table", tableName));
144         }
145         
146         public static void clickOnProperty(String propertyName) {
147                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on property %s ", propertyName));
148                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.InputsScreenService.RESOURCE_INSTANCE_PROPERTY_NAME.getValue() + propertyName);
149                 GeneralUIUtils.ultimateWait();
150         }
151         
152         
153         
154         
155         
156         
157
158 }