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