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.ArrayList;
24 import java.util.List;
25 import java.util.stream.Collectors;
27 import org.apache.commons.lang.WordUtils;
28 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
31 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
32 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
33 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
34 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
35 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
36 import org.openqa.selenium.By;
37 import org.openqa.selenium.WebElement;
38 import org.testng.collections.Lists;
40 import com.aventstack.extentreports.Status;
42 public class DeploymentArtifactPage extends GeneralPageElements {
44 public DeploymentArtifactPage() {
48 public static ResourceLeftMenu getLeftPanel() {
49 return new ResourceLeftMenu();
52 public static UploadArtifactPopup artifactPopup() {
53 return new UploadArtifactPopup();
56 protected static void addNewArtifact(ArtifactGroupTypeEnum artifactGroupType) {
57 switch (artifactGroupType) {
59 GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();
62 GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_INFORMATIONAL_ARTIFACT.getValue()).click();
69 public static void clickAddNewArtifact() {
70 addNewArtifact(ArtifactGroupTypeEnum.DEPLOYMENT);
73 public static void clickAddAnotherArtifact() {
74 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue()).click();
77 public static void clickEditArtifact(String artifactLabel) {
78 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + artifactLabel).click();
81 public static void clickEditEnvArtifact(String artifactLabel) {
82 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactLabel).click();
85 public static void clickDeleteArtifact(String artifactLabel) {
86 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting %s Artefact ",artifactLabel));
87 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + artifactLabel).click();
90 public static WebElement clickDownloadArtifact(String artifactLabel) {
91 WebElement downloadButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + artifactLabel);
93 return downloadButton;
96 public static void clickDownloadEnvArtifact(String envFileNameToDownload) {
97 ExtentTestActions.log(Status.INFO, String.format("Downloading the updated %s artifact for validate parameters with the response after the update...", envFileNameToDownload));
98 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + envFileNameToDownload);
99 ExtentTestActions.log(Status.INFO, String.format("%s Envartifact was downloaded successfully!", envFileNameToDownload));
102 public static void clickSaveEnvParameters() {
103 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.SAVE.getValue()).click();
104 GeneralUIUtils.ultimateWait();
107 public static WebElement getAddOtherArtifactButton(){
108 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue());
111 public static void clickOK(){
112 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.OK.getValue()).click();
113 GeneralUIUtils.getWebElementBy(By.className("flex-container"));
114 GeneralUIUtils.waitForAngular();
117 public static String getArtifactDescription(String artifactLabel) throws Exception {
118 clickOnArtifactDescription(artifactLabel); // open artifact
119 WebElement artifactDescriptionElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.GET_DEPLOYMENT_ARTIFACT_DESCRIPTION.getValue());
120 String artifactDesc = artifactDescriptionElement.getAttribute("value");
121 closeArtifactDescription(artifactLabel); // close artifact
125 public static void closeArtifactDescription(String artifactLabel) {
126 GeneralUIUtils.clickOnElementByTestId("popover-x-button");
129 public static WebElement clickOnArtifactDescription(String artifactLabel) throws Exception {
131 WebElement artifact = GeneralUIUtils.getWebElementByTestID("descriptionIcon_" + artifactLabel);
133 GeneralUIUtils.waitForLoader();
137 throw new Exception("Artifact " + artifactLabel + "is not found");
141 public static boolean checkElementsCountInTable(int expectedElementsCount) {
142 return GeneralPageElements.checkElementsCountInTable(expectedElementsCount + 1);
145 public static String[] verifyArtifactsExistInTable(String filepath, String vnfFile) throws Exception{
146 String[] artifactNamesFromZipFile = FileHandling.getArtifactsFromZip(filepath, vnfFile);
147 return verifyArtifactsExistInTable(artifactNamesFromZipFile);
150 public static String[] verifyArtifactsExistInTable(String[] artifactNamesFromZipFile) throws Exception{
151 if (artifactNamesFromZipFile != null){
152 checkArtifactsDisplayed(artifactNamesFromZipFile);
153 checkEnvArtifactsDisplayed();
156 return artifactNamesFromZipFile;
159 public static void checkArtifactsDisplayed(String[] artifactsFromZipFile) throws Exception {
160 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the artifacts in the table");
161 List<String> artifactList = Lists.newArrayList(artifactsFromZipFile).stream().filter(p -> !p.contains(".env")).map(p -> getVisualArtifactName(p)).collect(Collectors.toList());
163 // List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span.ng-binding:nth-of-type(2)");
164 List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span[data-tests-id^='artifactDisplayName']");
165 for (WebElement r : rows){
166 String artifactDisplayed = r.getAttribute("textContent").trim();
167 if (artifactList.contains(artifactDisplayed)){
168 artifactList.remove(artifactDisplayed);
170 else if (artifactDisplayed.toLowerCase().contains("license")){
171 artifactList.add(artifactDisplayed);
174 checkLicenseArtifactsDisplayed(artifactList);
177 throw new Exception("Table problem");
181 if (!artifactList.isEmpty()){
182 throw new Exception(String.format("missing the following artifact(s) : %s", artifactList.toString()));
186 public static void checkEnvArtifactsDisplayed() throws Exception {
187 List<WebElement> envRows;
188 List<WebElement> heatRows;
189 List<WebElement> heatNetRows;
190 List<WebElement> heatVolRows;
191 int envArtifactsSize = 0;
193 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the HEAT_ENV artifacts in the table");
196 envRows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id='HEAT_ENV']");
198 heatRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT']");
199 heatNetRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_NET']");
200 heatVolRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_VOL']");
202 envArtifactsSize = heatRows.size() + heatNetRows.size() + heatVolRows.size();
205 throw new Exception("Table problem");
208 if (envArtifactsSize !=envRows.size()){
209 throw new Exception(String.format("some env artifacts are missing... there is %s instead of %s", envRows.size(), envArtifactsSize));
214 public static void checkLicenseArtifactsDisplayed(List<String> rowsFromTable) throws Exception {
215 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the license artifacts in the table");
216 String vfLicense = getPreparedLicense(ArtifactTypeEnum.VF_LICENSE.getType());
217 String[] split = vfLicense.split(" ");
218 vfLicense = vfLicense.replaceAll(split[0], split[0].toUpperCase());
219 if (rowsFromTable.contains(vfLicense)){
220 rowsFromTable.remove(vfLicense);
223 String vendorLicense = getPreparedLicense(ArtifactTypeEnum.VENDOR_LICENSE.getType());
224 if (rowsFromTable.contains(vendorLicense)){
225 rowsFromTable.remove(vendorLicense);
230 public static String getPreparedLicense(String license) {
231 return WordUtils.capitalizeFully(license.replaceAll("_", " "));
235 private static String getVisualArtifactName(String artifactName) {
236 if (artifactName.contains(".")){
237 return artifactName.substring(0, artifactName.lastIndexOf("."));
242 public static void updateDescription(String newDescription, ArtifactInfo artefact) throws Exception{
243 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
244 DeploymentArtifactPage.clickEditArtifact(artefact.getArtifactLabel());
245 artifactPopup.insertDescription(newDescription);
246 artifactPopup.clickDoneButton();
249 public static List<String> getDeploymentArtifactsNamesWorkSpace() {
250 return GeneralUIUtils.getWebElementListText(GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue()));
253 //Get Artifact Type by Artifact Name.
254 public static String getArtifactType(String artifactName){
255 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue()+artifactName).getText();
258 public static List<String> getHeatParametersInUI(String dataTestId){
259 List<WebElement>elements;
260 List<String>Names=new ArrayList<>();
261 elements=GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
262 for (WebElement webElement : elements) {
263 String attributevalue=webElement.getAttribute("data-tests-id");
264 Names.add(attributevalue.replace("heatParameterName_", ""));
269 public static void searchBoxEnv(String parameterName) {
270 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").sendKeys(parameterName);
273 public static void clearSearchBoxEnv() {
274 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").clear();