re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / DeploymentArtifactPage.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * SDC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.sdc.ci.tests.pages;\r
22 \r
23 import com.aventstack.extentreports.Status;\r
24 import org.apache.commons.lang.WordUtils;\r
25 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;\r
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;\r
27 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;\r
28 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;\r
29 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;\r
30 import org.openecomp.sdc.ci.tests.utilities.FileHandling;\r
31 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;\r
32 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;\r
33 import org.openqa.selenium.By;\r
34 import org.openqa.selenium.WebElement;\r
35 import org.testng.collections.Lists;\r
36 \r
37 import java.util.ArrayList;\r
38 import java.util.List;\r
39 import java.util.stream.Collectors;\r
40 \r
41 public class DeploymentArtifactPage extends GeneralPageElements {\r
42 \r
43         public DeploymentArtifactPage() {\r
44                 super();\r
45         }\r
46 \r
47         public static ResourceLeftMenu getLeftPanel() {\r
48                 return new ResourceLeftMenu();\r
49         }\r
50 \r
51         public static UploadArtifactPopup artifactPopup() {\r
52                 return new UploadArtifactPopup();\r
53         }\r
54 \r
55         protected static void addNewArtifact(ArtifactGroupTypeEnum artifactGroupType) {\r
56                 switch (artifactGroupType) {\r
57                         case DEPLOYMENT:\r
58                         GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();\r
59                                 break;\r
60                         case INFORMATIONAL:\r
61                         GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_INFORMATIONAL_ARTIFACT.getValue()).click();\r
62                                 break;\r
63                         default:\r
64                                 break;\r
65                         }\r
66         }\r
67 \r
68         public static void clickAddNewArtifact() {\r
69                 addNewArtifact(ArtifactGroupTypeEnum.DEPLOYMENT);\r
70         }\r
71 \r
72         public static void clickAddAnotherArtifact() {\r
73                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue()).click();\r
74         }\r
75 \r
76         public static void clickEditArtifact(String artifactLabel) {\r
77                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + artifactLabel).click();\r
78         }\r
79         \r
80         public static void clickEditEnvArtifact(String artifactLabel) {\r
81                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactLabel).click();\r
82         }\r
83 \r
84         public static void hoverArtifact(String artifactLabel) {\r
85                 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactLabel);\r
86         }\r
87 \r
88         public static void clickDeleteArtifact(String artifactLabel) {\r
89                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting %s Artefact ",artifactLabel));\r
90                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + artifactLabel).click();\r
91         }\r
92 \r
93         public static WebElement clickDownloadArtifact(String artifactLabel) {\r
94                 WebElement downloadButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + artifactLabel);\r
95 \r
96                 return downloadButton;\r
97         }\r
98         \r
99         public static void clickDownloadEnvArtifact(String envFileNameToDownload) {\r
100                 ExtentTestActions.log(Status.INFO, String.format("Downloading the updated  %s artifact for validate parameters with the response after the update...", envFileNameToDownload));\r
101                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + envFileNameToDownload);\r
102                 ExtentTestActions.log(Status.INFO, String.format("%s Envartifact was downloaded successfully!", envFileNameToDownload));\r
103         }\r
104         \r
105         public static  void clickSaveEnvParameters() {\r
106                  GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.SAVE.getValue()).click();\r
107                  GeneralUIUtils.ultimateWait();\r
108         }\r
109 \r
110     public static  void clickCloseEnvParameters() {\r
111         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.CANCEL_BUTTON.getValue()).click();\r
112         GeneralUIUtils.ultimateWait();\r
113     }\r
114         \r
115         public static WebElement getAddOtherArtifactButton(){\r
116                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue());\r
117         }\r
118         \r
119         public static void clickOK(){\r
120                 SetupCDTest.getExtendTest().log(Status.INFO, "Artifact Page, Clicking OK");\r
121                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.OK.getValue()).click();\r
122                 GeneralUIUtils.getWebElementBy(By.className("flex-container"));\r
123                 GeneralUIUtils.waitForAngular();\r
124         }\r
125 \r
126         public static String getArtifactDescription(String artifactLabel) throws Exception {\r
127                 clickOnArtifactDescription(artifactLabel); // open artifact\r
128                 WebElement artifactDescriptionElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.GET_DEPLOYMENT_ARTIFACT_DESCRIPTION.getValue());\r
129                 String artifactDesc = artifactDescriptionElement.getAttribute("value");\r
130                 closeArtifactDescription(artifactLabel); // close artifact\r
131                 return artifactDesc;\r
132         }\r
133 \r
134         public static void closeArtifactDescription(String artifactLabel) {\r
135                 GeneralUIUtils.clickOnElementByTestId("popover-x-button");\r
136         }\r
137 \r
138         public static WebElement clickOnArtifactDescription(String artifactLabel) throws Exception {\r
139                 try{\r
140                         WebElement artifact = GeneralUIUtils.getWebElementByTestID("descriptionIcon_" + artifactLabel);\r
141                         artifact.click();\r
142                         GeneralUIUtils.waitForLoader();\r
143                         return artifact;\r
144                 }\r
145                 catch(Exception e){\r
146                         throw new Exception("Artifact " + artifactLabel + "is not found");\r
147                 }\r
148         }\r
149         \r
150         public static boolean checkElementsCountInTable(int expectedElementsCount) {\r
151                 return GeneralPageElements.checkElementsCountInTable(expectedElementsCount + 1);\r
152         }\r
153         \r
154         public static String[] verifyArtifactsExistInTable(String filepath, String vnfFile) throws Exception{\r
155                 String[] artifactNamesFromZipFile = FileHandling.getArtifactsFromZip(filepath, vnfFile);\r
156                 return verifyArtifactsExistInTable(artifactNamesFromZipFile);\r
157         }\r
158         \r
159         public static String[] verifyArtifactsExistInTable(String[] artifactNamesFromZipFile) throws Exception{\r
160                 if (artifactNamesFromZipFile != null){\r
161                         checkArtifactsDisplayed(artifactNamesFromZipFile);\r
162                         checkEnvArtifactsDisplayed();\r
163                 }\r
164                 \r
165                 return artifactNamesFromZipFile;\r
166         }\r
167 \r
168         public static void checkArtifactsDisplayed(String[] artifactsFromZipFile) throws Exception {\r
169                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the artifacts in the table");\r
170                 List<String> artifactList = Lists.newArrayList(artifactsFromZipFile).stream().filter(p -> !p.contains(".env")).map(p -> getVisualArtifactName(p)).collect(Collectors.toList());\r
171                 try{\r
172 //                      List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span.ng-binding:nth-of-type(2)");\r
173                         List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span[data-tests-id^='artifactDisplayName']");\r
174                         for (WebElement r : rows){\r
175                                 String artifactDisplayed = r.getAttribute("textContent").trim();\r
176                                 if (artifactList.contains(artifactDisplayed)){\r
177                                         artifactList.remove(artifactDisplayed);\r
178                                 }\r
179                                 else if (artifactDisplayed.toLowerCase().contains("license")){\r
180                                         artifactList.add(artifactDisplayed);\r
181                                 }\r
182                         }\r
183                         checkLicenseArtifactsDisplayed(artifactList);\r
184                 }\r
185                 catch(Exception e){\r
186                         throw new Exception("Table problem");\r
187                 }\r
188                 \r
189                 \r
190                 if (!artifactList.isEmpty()){\r
191                         throw new Exception(String.format("missing the following artifact(s) : %s", artifactList.toString()));\r
192                 }\r
193         }\r
194 \r
195         public static void checkEnvArtifactsDisplayed() throws Exception {\r
196                 List<WebElement> envRows;\r
197                 List<WebElement> heatRows;\r
198                 List<WebElement> heatNetRows;\r
199                 List<WebElement> heatVolRows;\r
200                 int envArtifactsSize = 0;\r
201                 \r
202                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the HEAT_ENV artifacts in the table");\r
203                 \r
204                 try{\r
205                         envRows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id='HEAT_ENV']");\r
206                         \r
207                         heatRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT']");\r
208                         heatNetRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_NET']");\r
209                         heatVolRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_VOL']");\r
210                         \r
211                         envArtifactsSize = heatRows.size() + heatNetRows.size() + heatVolRows.size();\r
212                 }\r
213                 catch(Exception e){\r
214                         throw new Exception("Table problem");\r
215                 }\r
216                 \r
217                 if (envArtifactsSize !=envRows.size()){\r
218                         throw new Exception(String.format("some env artifacts are missing... there is %s instead of %s", envRows.size(), envArtifactsSize));    \r
219                 }\r
220                 \r
221         }\r
222 \r
223         public static void checkLicenseArtifactsDisplayed(List<String> rowsFromTable) throws Exception {\r
224                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the license artifacts in the table");\r
225                 String vfLicense =   getPreparedLicense(ArtifactTypeEnum.VF_LICENSE.getType());\r
226                 String[] split = vfLicense.split(" ");\r
227                 vfLicense = vfLicense.replaceAll(split[0], split[0].toUpperCase());\r
228                 if (rowsFromTable.contains(vfLicense)){\r
229                         rowsFromTable.remove(vfLicense);\r
230                 }\r
231                 \r
232                 String vendorLicense = getPreparedLicense(ArtifactTypeEnum.VENDOR_LICENSE.getType());\r
233                 if (rowsFromTable.contains(vendorLicense)){ \r
234                         rowsFromTable.remove(vendorLicense);\r
235                 }\r
236 \r
237         }\r
238 \r
239         public static String getPreparedLicense(String license) {\r
240                 return WordUtils.capitalizeFully(license.replaceAll("_", " "));\r
241         }\r
242         \r
243 \r
244         private static String getVisualArtifactName(String artifactName) {\r
245                 if (artifactName.contains(".")){\r
246                         return artifactName.substring(0, artifactName.lastIndexOf("."));\r
247                 }\r
248                 return artifactName;\r
249         }\r
250         \r
251         public static void updateDescription(String newDescription, ArtifactInfo artefact) throws Exception{\r
252                 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);\r
253                 DeploymentArtifactPage.clickEditArtifact(artefact.getArtifactLabel());\r
254                 artifactPopup.insertDescription(newDescription);\r
255                 artifactPopup.clickDoneButton();\r
256         }\r
257         \r
258         public static List<String> getDeploymentArtifactsNamesWorkSpace() {\r
259                 return GeneralUIUtils.getWebElementListText(GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue()));\r
260         }\r
261         \r
262         //Get Artifact Type by Artifact Name.\r
263         public static String getArtifactType(String artifactName){\r
264                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue()+artifactName).getText();\r
265         }\r
266         \r
267         public static List<String> getHeatParametersInUI(String dataTestId){\r
268                 List<WebElement>elements;\r
269                 List<String>Names=new ArrayList<>();\r
270                 elements=GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);\r
271                                 for (WebElement webElement : elements) {\r
272                                         String attributevalue=webElement.getAttribute("data-tests-id");\r
273                                         Names.add(attributevalue.replace("heatParameterName_", ""));\r
274                                 }\r
275                 return Names;\r
276         }\r
277         \r
278         public static void searchBoxEnv(String parameterName) {\r
279                 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").sendKeys(parameterName);\r
280         }\r
281         \r
282         public static void clearSearchBoxEnv() {\r
283                 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").clear();\r
284         }\r
285 \r
286     public static void editHeatParamValue(String paramName, String value) throws Exception {\r
287         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Heat Params modal screen");\r
288         WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(paramName);\r
289 \r
290         clickOnHeatParam(paramName);\r
291         valueTextbox.clear();\r
292         SetupCDTest.getExtendTest().log(Status.INFO, "Editing " + paramName + " value on Heat Params modal screen");\r
293         valueTextbox.sendKeys(value);\r
294         GeneralUIUtils.ultimateWait();\r
295 \r
296     }\r
297 \r
298     public static void clickOnDeleteHeatParamValue(String paramName) throws Exception {\r
299         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Properties screen");\r
300         String value = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.EnvParameterView.ENV_CURRENT_VALUE.getValue() + paramName).getAttribute("value");\r
301         if (value!=null) {\r
302             GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DELETE_PARAMETER_OF_ARTIFACT.getValue() + paramName);\r
303             GeneralUIUtils.ultimateWait();\r
304             SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is deleted");\r
305         }\r
306         SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is empty and cannot be deleted");\r
307     }\r
308 \r
309     public static void clickOnHeatParam(String paramName)throws Exception {\r
310 \r
311         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", paramName));\r
312         GeneralUIUtils.clickOnElementByTestId(paramName);\r
313         GeneralUIUtils.ultimateWait();\r
314         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());\r
315     }\r
316 \r
317 }\r