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.onap.sdc.frontend.ci.tests.pages;
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.DeploymentScreen;
26 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
27 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
28 import org.onap.sdc.frontend.ci.tests.utilities.ResourceUIUtils;
29 import org.openqa.selenium.By;
30 import org.openqa.selenium.WebElement;
32 import java.util.HashMap;
33 import java.util.List;
36 public class DeploymentPage {
38 public DeploymentPage() {
42 public static List<WebElement> getGroupMembersList(String instanceName) {
43 List<WebElement> propertyRows = null;
44 clickOnModuleName(instanceName);
45 propertyRows = getVisibleMembers();
49 public static void clickOnModuleName(String instanceName) {
50 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", instanceName));
51 GeneralUIUtils.clickOnElementByText(instanceName);
52 GeneralUIUtils.ultimateWait();
55 public static List<WebElement> getVisibleMembers() {
56 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='hierarchy-module-member-list']"));
57 for (WebElement instance : instancesFromTable) {
58 Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
59 if (!parentAttributes.toString().contains("hidden")) {
60 return instance.findElements(By.cssSelector("div[class^='expand-collapse-sub-title']"));
66 public static void clickOnProperties() throws Exception {
67 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Properties button"));
68 GeneralUIUtils.clickOnElementByCSS(DataTestIdEnum.DeploymentScreen.BUTTON_PROPERTIES.getValue());
69 GeneralUIUtils.ultimateWait();
72 public static void clickOnArtifacts() throws Exception {
73 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Artifacts button"));
74 GeneralUIUtils.clickOnElementByCSS(DataTestIdEnum.DeploymentScreen.BUTTON_ARTIFACTS.getValue());
75 GeneralUIUtils.ultimateWait();
78 public static void clickOnSaveButton() {
79 clickInDeployment(DataTestIdEnum.DeploymentScreen.SAVE);
80 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
83 public static void clickOnCancelButton() {
84 clickInDeployment(DataTestIdEnum.DeploymentScreen.CANCEL);
85 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
88 public static void clickOnXIcon() {
89 clickInDeployment(DataTestIdEnum.DeploymentScreen.X_BUTTON);
90 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
93 public static void clickOnEditIcon() {
94 clickInDeployment(DataTestIdEnum.DeploymentScreen.PENCIL_ICON);
97 public static void clickOnProperty(WebElement property) {
98 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s propertie ...", property.getText()));
100 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.POPUP_FORM.getValue());
103 private static void clickInDeployment(DataTestIdEnum.DeploymentScreen element) {
104 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s ...", element.getValue()));
105 GeneralUIUtils.clickOnElementByTestId(element.getValue());
106 //GeneralUIUtils.ultimateWait();
109 public static List<WebElement> getPropertyNames() throws Exception {
111 return GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.PROPERTY_NAMES.getValue());
114 public static List<WebElement> getArtifactNames() throws Exception {
116 return GeneralUIUtils.getInputElements(DataTestIdEnum.DeploymentScreen.ARTIFACT_NAME.getValue());
119 public static String updateModuleName(String currentModuleName, String newModuleName) throws Exception {
120 GeneralUIUtils.ultimateWait();
121 ResourceUIUtils.clickOnElementByText(currentModuleName, null);
122 GeneralUIUtils.ultimateWait();
124 WebElement moduleNameField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue());
125 String oldModuleName = moduleNameField.getAttribute("value");
126 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating %s module name ...", currentModuleName));
127 moduleNameField.clear();
128 GeneralUIUtils.ultimateWait();
129 moduleNameField.sendKeys(newModuleName);
130 GeneralUIUtils.ultimateWait();
132 String newReconstructedModuleName = reconstructModuleName(currentModuleName.split("\\.\\."), newModuleName);
133 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Name of element instance changed from %s to %s", currentModuleName, newReconstructedModuleName));
134 return oldModuleName;
137 public static String reconstructModuleName(String[] splittedName, String middleName) {
139 StringBuilder builder = new StringBuilder();
140 for (String s : splittedName) {
142 builder.append(middleName);
147 builder.append("..");
151 return builder.toString();
154 public static List<WebElement> getVisibleModulesService() {
155 List<WebElement> instancesFromTable = GeneralUIUtils.getDriver().findElements(By.cssSelector("div[class^='hierarchy-modules-list']"));
156 for (WebElement instance : instancesFromTable) {
157 Object parentAttributes = GeneralUIUtils.getAllElementAttributes(instance);
158 if (!parentAttributes.toString().contains("hidden")) {
159 return instance.findElements(By.cssSelector("span[class^='expand-collapse-title-text']"));
165 public static List<WebElement> getInstanceModulesList(String instanceName) {
166 List<WebElement> propertyRows = null;
167 ResourceUIUtils.clickOnElementByText(instanceName, null);
168 GeneralUIUtils.ultimateWait();
169 propertyRows = getVisibleModulesService();
173 public static String getGroupVersion() throws Exception {
174 return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-version']").get(0).getText();
177 public static String getModuleID() throws Exception {
178 return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-group-uuid'] span[class^='small-font']").get(0).getText();
181 public static Map<String, HashMap<String, String>> collectMetaDataFromUI() throws Exception {
182 ResourceGeneralPage.getLeftMenu().moveToDeploymentViewScreen();
183 Map<String, HashMap<String, String>> deploymentViewMetaData = new HashMap<String, HashMap<String, String>>();
184 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS("span[class^='expand-collapse-title-text']");
185 for (WebElement moduleRow : moduleRowsFromTable) {
186 HashMap<String, String> tempGroupMap = new HashMap<String, String>();
187 String moduleRowText = moduleRow.getText();
188 GeneralUIUtils.clickOnElementByText(moduleRowText);
189 tempGroupMap.put("moduleID", getModuleID());
190 tempGroupMap.put("version", DeploymentPage.getGroupVersion().split(":")[1].trim());
191 deploymentViewMetaData.put(moduleRowText.split("\\.\\.")[1], tempGroupMap);
192 GeneralUIUtils.clickOnElementByText(moduleRowText);
194 return deploymentViewMetaData;
197 public static void updateAndCancel(String newModuleName, DataTestIdEnum.DeploymentScreen buttonToClick) {
198 WebElement moduleNameField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue());
199 String oldModuleName = moduleNameField.getAttribute("value");
200 moduleNameField.clear();
201 GeneralUIUtils.ultimateWait();
202 moduleNameField.sendKeys(newModuleName);
203 GeneralUIUtils.ultimateWait();
204 if (buttonToClick.equals(DataTestIdEnum.DeploymentScreen.X_BUTTON)) {
207 clickOnCancelButton();
211 public static String getPropertyValueFromPropertiesList(String property) throws InterruptedException {
212 List<WebElement> propertyDataElements = GeneralUIUtils.getElementsByCSS("div[class^='list-item property-data']");
213 for (WebElement propertyDataElement : propertyDataElements) {
214 WebElement propertyNameElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, DeploymentScreen.PROPERTY_NAMES.getValue());
215 if (propertyNameElement.getText().equals(property)) {
216 WebElement propertyValueElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, String.format("div[data-tests-id='%s']", DeploymentScreen.PROPERTY_SCHEMA_TYPE.getValue()));
217 return propertyValueElement.getText().trim().split(":")[1].trim();
223 public static List<WebElement> getPropertyErrorValidationMessdge() throws Exception {
224 List<WebElement> propertyErrorElements = GeneralUIUtils.getElementsByCSS("div[class='input-error'] span[class='ng-scope']");
225 return propertyErrorElements;
228 public static boolean isPropertySaveButtonDisabled() {
229 WebElement saveButtonElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.SAVE.getValue());
230 return GeneralUIUtils.isElementDisabled(saveButtonElement);