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