[SDC-29] rebase continue work to align source
[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 java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.stream.Collector;
27 import java.util.stream.Collectors;
28
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;
37
38
39 import com.aventstack.extentreports.Status;
40
41 public class DeploymentPage  {
42         
43         public DeploymentPage() {
44                 super();                
45         }
46         
47         public static List<WebElement> getGroupMembersList(String instanceName) {
48                 List<WebElement> propertyRows = null;
49                 clickOnModuleName(instanceName);
50                 propertyRows = getVisibleMembers();
51                 return propertyRows;
52         }
53
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();
58         }
59
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']"));
66                         }
67                 }
68                 return null;
69         }
70         
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();  
75         }
76         
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();  
81         }
82         
83         public static void clickOnSaveButton(){
84                 clickInDeployment(DataTestIdEnum.DeploymentScreen.SAVE);
85                 GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
86         }
87         
88     public static void clickOnCancelButton(){
89         clickInDeployment(DataTestIdEnum.DeploymentScreen.CANCEL);
90         GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
91         }
92     
93     public static void clickOnXIcon(){
94         clickInDeployment(DataTestIdEnum.DeploymentScreen.X_BUTTON);
95         GeneralUIUtils.waitForElementInVisibilityByTestId(By.className("popover-inner"));
96     }
97     
98     public static void clickOnEditIcon(){
99         clickInDeployment(DataTestIdEnum.DeploymentScreen.PENCIL_ICON);
100     }
101     
102     public static void clickOnProperty(WebElement property) {
103         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s propertie ...", property.getText()));
104         property.click();
105                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPageEnum.POPUP_FORM.getValue());
106         }
107     
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();
112     }
113     
114     public static List<WebElement> getPropertyNames() throws Exception{
115         clickOnProperties();
116         return GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.PROPERTY_NAMES.getValue());
117     }
118     
119     public static List<WebElement> getArtifactNames() throws Exception{
120         clickOnArtifacts();
121         return GeneralUIUtils.getInputElements(DataTestIdEnum.DeploymentScreen.ARTIFACT_NAME.getValue());
122     }
123     
124     public static String updateModuleName(String currentModuleName, String newModuleName) throws Exception {
125                 GeneralUIUtils.ultimateWait();
126                 ResourceUIUtils.clickOnElementByText(currentModuleName, null);
127                 GeneralUIUtils.ultimateWait();
128                 clickOnEditIcon();
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();
136                 clickOnSaveButton();    
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;
140         }
141     
142     public static String reconstructModuleName(String[] splittedName, String middleName){
143         int i = 0;
144         StringBuilder builder = new StringBuilder();
145         for(String s : splittedName) {
146             if (i == 1){
147                 builder.append(middleName);
148             } else {
149                 builder.append(s);
150             }
151             if (i < 2 ){
152                 builder.append("..");
153             }
154             i++;
155         }
156         return builder.toString();
157     }
158     
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']"));
165                         }
166                 }
167                 return null;
168         }
169     
170     public static List<WebElement> getInstanceModulesList(String instanceName) {
171                 List<WebElement> propertyRows = null;
172                 ResourceUIUtils.clickOnElementByText(instanceName, null);
173                 GeneralUIUtils.ultimateWait();
174                 propertyRows = getVisibleModulesService();
175                 return propertyRows;
176         }
177     
178     public static String getGroupVersion() throws Exception{
179         return GeneralUIUtils.getElementsByCSS("div[data-tests-id='selected-module-version']").get(0).getText();
180     }
181     
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();
184     }   
185     
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);
198                 }
199                 return deploymentViewMetaData;
200         }
201     
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))
210                     clickOnXIcon();
211                 else
212                         clickOnCancelButton();
213     }
214     
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();
222                 }
223         }
224         return null;
225     }
226     
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;
230     }
231     
232     public static boolean isPropertySaveButtonDisabled(){
233         WebElement saveButtonElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.PropertiesPopupEnum.SAVE.getValue());
234         return GeneralUIUtils.isElementDisabled(saveButtonElement);
235     }
236     
237     
238     
239 }