2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.pages;
23 import java.util.List;
24 import java.util.stream.Collectors;
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;
34 import com.aventstack.extentreports.Status;
36 public class InputsPage extends GeneralPageElements {
43 public static List<WebElement> getInstancePropertiesList(String instanceName) {
44 List<WebElement> propertyRows = null;
45 GeneralUIUtils.clickOnElementByText(instanceName);
46 GeneralUIUtils.ultimateWait();
47 propertyRows = getVisibleProperites();
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"));
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();
73 public static List<WebElement> getInstanceInputsList(String instanceName) {
74 List<WebElement> inputRows = null;
75 GeneralUIUtils.clickOnElementByText(instanceName);
76 GeneralUIUtils.ultimateWait();
77 inputRows = getVisibleInputs(inputRows);
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"));
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();
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");
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;
115 throw new TestException(String.format("%s input don't exist", expectedInputName));
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();
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());
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)){
143 throw new TestException(String.format("Can't find %s table", tableName));
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();