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.HashMap;
24 import java.util.List;
26 import java.util.stream.Collector;
27 import java.util.stream.Collectors;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.DeploymentScreen;
31 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
32 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
34 import org.openqa.selenium.By;
35 import org.openqa.selenium.WebElement;
36 import static org.testng.Assert.assertTrue;
39 import com.aventstack.extentreports.Status;
41 public class DeploymentPage {
43 public DeploymentPage() {
47 public static List<WebElement> getGroupMembersList(String instanceName) {
48 List<WebElement> propertyRows = null;
49 clickOnModuleName(instanceName);
50 propertyRows = getVisibleMembers();
54 public static void clickOnModuleName(String instanceName) {
55 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", instanceName));
56 GeneralUIUtils.clickOnElementByText(instanceName);
57 GeneralUIUtils.ultimateWait();
60 public static List<WebElement> getVisibleMembers() {
61 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='hierarchy-module-member-list']"));
62 for (WebElement instance : instancesFromTable){
63 Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
64 if (!parentAttributes.toString().contains("hidden")){
65 return instance.findElements(By.cssSelector("div[class^='expand-collapse-sub-title']"));
71 public static void clickOnProperties() throws Exception{
72 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Properties button"));
73 GeneralUIUtils.clickOnElementByCSS(DataTestIdEnum.DeploymentScreen.BUTTON_PROPERTIES.getValue());
74 GeneralUIUtils.ultimateWait();
77 public static void clickOnArtifacts() throws Exception{
78 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Artifacts button"));
79 GeneralUIUtils.clickOnElementByCSS(DataTestIdEnum.DeploymentScreen.BUTTON_ARTIFACTS.getValue());
80 GeneralUIUtils.ultimateWait();
83 public static void clickOnSaveButton(){
84 clickInDeployment(DataTestIdEnum.DeploymentScreen.SAVE);
85 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
88 public static void clickOnCancelButton(){
89 clickInDeployment(DataTestIdEnum.DeploymentScreen.CANCEL);
90 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
93 public static void clickOnXIcon(){
94 clickInDeployment(DataTestIdEnum.DeploymentScreen.X_BUTTON);
95 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
98 public static void clickOnEditIcon(){
99 clickInDeployment(DataTestIdEnum.DeploymentScreen.PENCIL_ICON);
102 public static void clickOnProperty(WebElement property) {
103 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s propertie ...", property.getText()));
105 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.POPUP_FORM.getValue());
108 private static void clickInDeployment(DataTestIdEnum.DeploymentScreen element){
109 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s ...", element.getValue()));
110 GeneralUIUtils.clickOnElementByTestId(element.getValue());
111 GeneralUIUtils.ultimateWait();
114 public static List<WebElement> getPropertyNames() throws Exception{
116 return GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.PROPERTY_NAMES.getValue());
119 public static List<WebElement> getArtifactNames() throws Exception{
121 return GeneralUIUtils.getInputElements(DataTestIdEnum.DeploymentScreen.ARTIFACT_NAME.getValue());
124 public static String updateModuleName(String currentModuleName, String newModuleName) throws Exception {
125 GeneralUIUtils.ultimateWait();
126 ResourceUIUtils.clickOnElementByText(currentModuleName, null);
127 GeneralUIUtils.ultimateWait();
129 WebElement moduleNameField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue());
130 String oldModuleName = moduleNameField.getAttribute("value");
131 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating %s module name ...", currentModuleName));
132 moduleNameField.clear();
133 GeneralUIUtils.ultimateWait();
134 moduleNameField.sendKeys(newModuleName);
135 GeneralUIUtils.ultimateWait();
137 String newReconstructedModuleName = reconstructModuleName(currentModuleName.split("\\.\\."), newModuleName);
138 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Name of element instance changed from %s to %s", currentModuleName, newReconstructedModuleName));
139 return oldModuleName;
142 public static String reconstructModuleName(String[] splittedName, String middleName){
144 StringBuilder builder = new StringBuilder();
145 for(String s : splittedName) {
147 builder.append(middleName);
152 builder.append("..");
156 return builder.toString();
159 public static List<WebElement> getVisibleModulesService() {
160 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='hierarchy-modules-list']"));
161 for (WebElement instance : instancesFromTable){
162 Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
163 if (!parentAttributes.toString().contains("hidden")){
164 return instance.findElements(By.cssSelector("span[class^='expand-collapse-title-text']"));
170 public static List<WebElement> getInstanceModulesList(String instanceName) {
171 List<WebElement> propertyRows = null;
172 ResourceUIUtils.clickOnElementByText(instanceName, null);
173 GeneralUIUtils.ultimateWait();
174 propertyRows = getVisibleModulesService();
178 public static String getGroupVersion() throws Exception{
179 return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-version']").get(0).getText();
182 public static String getModuleID() throws Exception{
183 return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-group-uuid'] span[class^='small-font']").get(0).getText();
186 public static Map<String, HashMap<String, String>> collectMetaDataFromUI() throws Exception{
187 ResourceGeneralPage.getLeftMenu().moveToDeploymentViewScreen();
188 Map<String, HashMap<String, String>> deploymentViewMetaData = new HashMap<String, HashMap<String, String>>();
189 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS("span[class^='expand-collapse-title-text']");
190 for(WebElement moduleRow :moduleRowsFromTable){
191 HashMap<String, String> tempGroupMap = new HashMap<String, String>();
192 String moduleRowText = moduleRow.getText();
193 GeneralUIUtils.clickOnElementByText(moduleRowText);
194 tempGroupMap.put("moduleID", getModuleID());
195 tempGroupMap.put("version", DeploymentPage.getGroupVersion().split(":")[1].trim());
196 deploymentViewMetaData.put(moduleRowText.split("\\.\\.")[1], tempGroupMap);
197 GeneralUIUtils.clickOnElementByText(moduleRowText);
199 return deploymentViewMetaData;
202 public static void updateAndCancel(String newModuleName, DataTestIdEnum.DeploymentScreen buttonToClick){
203 WebElement moduleNameField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue());
204 String oldModuleName = moduleNameField.getAttribute("value");
205 moduleNameField.clear();
206 GeneralUIUtils.ultimateWait();
207 moduleNameField.sendKeys(newModuleName);
208 GeneralUIUtils.ultimateWait();
209 if (buttonToClick.equals(DataTestIdEnum.DeploymentScreen.X_BUTTON))
212 clickOnCancelButton();
215 public static String getPropertyValueFromPropertiesList(String property) throws InterruptedException{
216 List<WebElement> propertyDataElements = GeneralUIUtils.getElementsByCSS("div[class^='list-item property-data']");
217 for(WebElement propertyDataElement: propertyDataElements){
218 WebElement propertyNameElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, DeploymentScreen.PROPERTY_NAMES.getValue());
219 if (propertyNameElement.getText().equals(property)){
220 WebElement propertyValueElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, String.format("div[data-tests-id='%s']", DeploymentScreen.PROPERTY_SCHEMA_TYPE.getValue()));
221 return propertyValueElement.getText().trim().split(":")[1].trim();
227 public static List<WebElement> getPropertyErrorValidationMessdge() throws Exception{
228 List<WebElement> propertyErrorElements = GeneralUIUtils.getElementsByCSS("div[class='input-error'] span[class='ng-scope']");
229 return propertyErrorElements;
232 public static boolean isPropertySaveButtonDisabled(){
233 WebElement saveButtonElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.SAVE.getValue());
234 return GeneralUIUtils.isElementDisabled(saveButtonElement);