re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / DeploymentPage.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.DeploymentScreen;
26 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
27 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
28 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
29 import org.openqa.selenium.By;
30 import org.openqa.selenium.WebElement;
31
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 public class DeploymentPage  {
37         
38         public DeploymentPage() {
39                 super();                
40         }
41         
42         public static List<WebElement> getGroupMembersList(String instanceName) {
43                 List<WebElement> propertyRows = null;
44                 clickOnModuleName(instanceName);
45                 propertyRows = getVisibleMembers();
46                 return propertyRows;
47         }
48
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();
53         }
54
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']"));
61                         }
62                 }
63                 return null;
64         }
65         
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();  
70         }
71         
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();  
76         }
77         
78         public static void clickOnSaveButton(){
79                 clickInDeployment(DataTestIdEnum.DeploymentScreen.SAVE);
80                 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
81         }
82         
83     public static void clickOnCancelButton(){
84         clickInDeployment(DataTestIdEnum.DeploymentScreen.CANCEL);
85         GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
86         }
87     
88     public static void clickOnXIcon(){
89         clickInDeployment(DataTestIdEnum.DeploymentScreen.X_BUTTON);
90         GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
91     }
92     
93     public static void clickOnEditIcon(){
94         clickInDeployment(DataTestIdEnum.DeploymentScreen.PENCIL_ICON);
95     }
96     
97     public static void clickOnProperty(WebElement property) {
98         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s propertie ...", property.getText()));
99         property.click();
100                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.POPUP_FORM.getValue());
101         }
102     
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();
107     }
108     
109     public static List<WebElement> getPropertyNames() throws Exception{
110         clickOnProperties();
111         return GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.PROPERTY_NAMES.getValue());
112     }
113     
114     public static List<WebElement> getArtifactNames() throws Exception{
115         clickOnArtifacts();
116         return GeneralUIUtils.getInputElements(DataTestIdEnum.DeploymentScreen.ARTIFACT_NAME.getValue());
117     }
118     
119     public static String updateModuleName(String currentModuleName, String newModuleName) throws Exception {
120                 GeneralUIUtils.ultimateWait();
121                 ResourceUIUtils.clickOnElementByText(currentModuleName, null);
122                 GeneralUIUtils.ultimateWait();
123                 clickOnEditIcon();
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();
131                 clickOnSaveButton();    
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;
135         }
136     
137     public static String reconstructModuleName(String[] splittedName, String middleName){
138         int i = 0;
139         StringBuilder builder = new StringBuilder();
140         for(String s : splittedName) {
141             if (i == 1){
142                 builder.append(middleName);
143             } else {
144                 builder.append(s);
145             }
146             if (i < 2 ){
147                 builder.append("..");
148             }
149             i++;
150         }
151         return builder.toString();
152     }
153     
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']"));
160                         }
161                 }
162                 return null;
163         }
164     
165     public static List<WebElement> getInstanceModulesList(String instanceName) {
166                 List<WebElement> propertyRows = null;
167                 ResourceUIUtils.clickOnElementByText(instanceName, null);
168                 GeneralUIUtils.ultimateWait();
169                 propertyRows = getVisibleModulesService();
170                 return propertyRows;
171         }
172     
173     public static String getGroupVersion() throws Exception{
174         return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-version']").get(0).getText();
175     }
176     
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();
179     }   
180     
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);
193                 }
194                 return deploymentViewMetaData;
195         }
196     
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))
205                     clickOnXIcon();
206                 else
207                         clickOnCancelButton();
208     }
209     
210     public static String getPropertyValueFromPropertiesList(String property) throws InterruptedException{
211         List<WebElement> propertyDataElements = GeneralUIUtils.getElementsByCSS("div[class^='list-item property-data']");
212         for(WebElement propertyDataElement: propertyDataElements){
213                 WebElement propertyNameElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, DeploymentScreen.PROPERTY_NAMES.getValue());
214                 if (propertyNameElement.getText().equals(property)){
215                         WebElement propertyValueElement = GeneralUIUtils.getElementfromElementByCSS(propertyDataElement, String.format("div[data-tests-id='%s']", DeploymentScreen.PROPERTY_SCHEMA_TYPE.getValue()));
216                         return propertyValueElement.getText().trim().split(":")[1].trim();
217                 }
218         }
219         return null;
220     }
221     
222     public static List<WebElement> getPropertyErrorValidationMessdge() throws Exception{
223         List<WebElement> propertyErrorElements = GeneralUIUtils.getElementsByCSS("div[class='input-error'] span[class='ng-scope']");
224         return propertyErrorElements;
225     }
226     
227     public static boolean isPropertySaveButtonDisabled(){
228         WebElement saveButtonElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.SAVE.getValue());
229         return GeneralUIUtils.isElementDisabled(saveButtonElement);
230     }
231     
232     
233     
234 }