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.utilities;
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
25 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.HeatWithParametersDefinition;
28 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
29 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
30 import org.openecomp.sdc.ci.tests.pages.InformationalArtifactPage;
31 import org.openecomp.sdc.ci.tests.pages.UploadArtifactPopup;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.WebElement;
34 import org.testng.Assert;
37 import java.io.IOException;
38 import java.util.HashMap;
39 import java.util.List;
42 import static org.junit.Assert.assertTrue;
44 public final class ArtifactUIUtils {
46 private static final String PARAMETERS = "parameters";
47 private static final String DATA_TESTS_ID = "//*[@data-tests-id='";
49 private ArtifactUIUtils() {
52 public static void fillAndAddNewArtifactParameters(ArtifactInfo artifactInfo) throws Exception {
53 UploadArtifactPopup artifactPopup = new UploadArtifactPopup();
54 fillAndAddNewArtifactParameters(artifactInfo, artifactPopup);
57 public static void fillAndAddNewArtifactParameters(ArtifactInfo artifactInfo, UploadArtifactPopup artifactPopup) throws Exception {
58 artifactPopup.defineArtifactLabel(artifactInfo.getArtifactLabel());
59 artifactPopup.selectArtifactType(artifactInfo.getArtifactType());
60 artifactPopup.insertDescription(artifactInfo.getDescription());
61 artifactPopup.loadFile(artifactInfo.getFilepath(), artifactInfo.getFilename());
62 artifactPopup.clickDoneButton();
63 SetupCDTest.getExtendTest().log(Status.INFO, String.format("A new artifact of type %s was added", artifactInfo.getArtifactType()));
66 public static void fillAndAddNewEnvArtifactParameters(ArtifactInfo artifactInfo, UploadArtifactPopup artifactPopup) throws Exception {
67 artifactPopup.insertDescription(artifactInfo.getDescription());
68 artifactPopup.loadFile(artifactInfo.getFilepath(), artifactInfo.getFilename());
69 artifactPopup.clickDoneButton();
70 SetupCDTest.getExtendTest().log(Status.INFO, String.format("ENV parameters %s artifact updated ", artifactInfo.getArtifactType()));
73 public static void fillPlaceHolderInformationalArtifact(DataTestIdEnum.InformationalArtifactsPlaceholders artifactLabel, String filepath, String filename, String description) throws Exception {
74 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
75 InformationalArtifactPage.artifactPopup().loadFile(filepath, filename);
76 InformationalArtifactPage.artifactPopup().insertDescription(description);
77 InformationalArtifactPage.artifactPopup().clickDoneButton();
80 public static void fillPlaceHolderInformationalArtifact(DataTestIdEnum.InformationalArtifactsService artifactLabel,
81 String filepath, String filename, String description) throws Exception {
82 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
83 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
84 artifactPopup.loadFile(filepath, filename);
85 artifactPopup.insertDescription(description);
86 artifactPopup.clickDoneButton();
89 public static void fillPlaceHolderAPIArtifact(DataTestIdEnum.APIArtifactsService artifactLabel,
90 String filepath, String filename, String description, String url) throws Exception {
91 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
92 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
93 artifactPopup.loadFile(filepath, filename);
94 artifactPopup.insertURL(url);
95 artifactPopup.insertDescription(description);
96 artifactPopup.clickDoneButton();
99 public static void validateArtifactNameVersionType(String artifactLabel, String artifactVersion, String artifactType) {
100 if (!GeneralUIUtils.getDriver().findElement(By.xpath(DATA_TESTS_ID + DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactLabel)) {
101 SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact label not equal - this warning represent defect.");
103 if (artifactVersion != null) {
104 if (!GeneralUIUtils.getDriver().findElement(By.xpath(DATA_TESTS_ID + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactVersion)) {
105 SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact version not equal - this warning represent defect.");
108 if (artifactType != null) {
109 if (!GeneralUIUtils.getDriver().findElement(By.xpath(DATA_TESTS_ID + DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactType)) {
110 SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact type not equal - this warning represent defect.");
115 public static void validateExistArtifactOnDeploymentInformationPage(String expectedArtifactLabel, String artifactUUID, String artifactVersion, String artifactType, boolean isDownloadable, boolean isEditable, boolean isDeletable, boolean isArtifactParametersEditable) {
117 String dataTestId = DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + expectedArtifactLabel;
119 List<WebElement> artifactElements = GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
120 Assert.assertEquals(artifactElements.size(), 1, "There are more then one artifact named " + expectedArtifactLabel);
122 WebElement artifact = artifactElements.get(0);
123 String actualArtifactLabel = GeneralUIUtils.getTextContentAttributeValue(artifact).trim();
124 Assert.assertEquals(actualArtifactLabel, expectedArtifactLabel);
126 if (artifactUUID != null) {
127 WebElement uuid = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + expectedArtifactLabel);
128 Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(uuid).trim(), artifactUUID, "Artifact uuid not equal.");
130 if (artifactVersion != null) {
131 WebElement version = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + expectedArtifactLabel);
132 Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(version).trim(), artifactVersion, "Artifact version not equal.");
134 if (artifactType != null) {
135 WebElement type = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + expectedArtifactLabel);
136 Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(type).trim(), artifactType, "Artifact type not equal.");
138 if (isArtifactParametersEditable) {
139 Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that parameters edit button enabled.");
141 Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that parameters edit button disabled.");
143 if (isDownloadable) {
144 Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that download button enabled.");
146 Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that download button disabled.");
149 Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that edit button enabled.");
151 Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that edit button disabled.");
154 Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that delete button enabled.");
156 Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that delete button disabled.");
160 public static void validateNotExistArtifactOnDeploymentInformationPage(String artifactLabel) {
161 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel), false);
164 public static void validateExistArtifactOnCompositionRightMenuDeploymentInformationPage(String fileName, String artifactDisplayedName,
165 boolean isUpdateable, boolean isParametersEditable, boolean isDownloadable, boolean isDeleteable) {
166 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName).getText(), fileName);
167 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName).getText(), artifactDisplayedName);
169 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
171 if (isParametersEditable) {
172 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), true, "Expect that parameters edit button enabled.");
174 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), false, "Expect that parameters edit button disabled.");
176 if (isDownloadable) {
177 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), true, "Expect that download button enabled.");
179 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), false, "Expect that download button disabled.");
182 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), true, "Expect that delete button enabled.");
184 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), false, "Expect that delete button disabled.");
187 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
188 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), true, "Expect that edit button enabled.");
189 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPopup.DONE_BUTTON.getValue());
190 GeneralUIUtils.waitForElementInVisibilityByTestId(DataTestIdEnum.ArtifactPopup.DONE_BUTTON.getValue());
192 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
193 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false, "Expect that edit button disabled.");
198 public static void validateNotExistArtifactOnCompositionRightMenuDeploymentInformationPage(String artifactDisplayedName) {
199 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName), false);
202 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile, String dataTestId) throws Exception {
203 GeneralUIUtils.hoverOnAreaByTestId(dataTestId);
204 return verifyUpdatedEnvParameters(pairToUpdate, updateEnvFile);
207 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile) throws Exception {
209 String heatDisplayName = pairToUpdate.getHeatArtifactDisplayName();
210 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + heatDisplayName);
211 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
213 String pattern = PARAMETERS;
214 Map<String, Object> mapUpdetedEnvFile = FileHandling.parseYamlFileToMapByPattern(updateEnvFile, pattern);
215 Map<String, Object> mapDownloadedEnvFile = FileHandling.parseYamlFileToMapByPattern(latestFilefromDir, pattern);
217 SetupCDTest.getExtendTest().log(Status.INFO, "Going to check, that ENV file was updated ...");
218 assertTrue("File" + latestFilefromDir.getName() + " contains different parameters number from expected file", mapDownloadedEnvFile.size() == mapUpdetedEnvFile.size());
219 assertTrue("Updated file contains not updated parameters value", mapDownloadedEnvFile.entrySet().containsAll(mapUpdetedEnvFile.entrySet()));
220 return latestFilefromDir;
224 * compare heat env files by pattern ("parameters")
226 * @param expectedFile
231 public static void compareYamlFilesByPattern(File expectedFile, File actualFile, String pattern) throws Exception {
233 Map<String, Object> mapExpectedFile = FileHandling.parseYamlFileToMapByPattern(expectedFile, pattern);
234 Map<String, Object> mapActualFile = FileHandling.parseYamlFileToMapByPattern(actualFile, pattern);
235 SetupCDTest.getExtendTest().log(Status.INFO, "Going to compare file " + expectedFile.getName());
236 assertTrue("File " + actualFile.getName() + " contains different parameters number from expected file", mapActualFile.size() == mapExpectedFile.size());
237 assertTrue("File " + actualFile.getName() + " does not contains all expected parameters", mapActualFile.entrySet().containsAll(mapExpectedFile.entrySet()));
240 public static void compareYamlParametersByPattern(Map<String, Object> mapExpectedProperties, File actualFileProperties, String pattern) throws Exception {
242 Map<String, Object> mapActualFileProerties = FileHandling.parseYamlFileToMapByPattern(actualFileProperties, pattern);
243 SetupCDTest.getExtendTest().log(Status.INFO, "Going to compare files ...");
244 assertTrue("Actual file contains different parameters number from expected file", mapActualFileProerties.size() == mapExpectedProperties.size());
245 Map<String, Object> newMap = new HashMap<>(mapActualFileProerties);
246 assertTrue("Actual file does not contains all expected parameters", newMap.entrySet().containsAll(mapExpectedProperties.entrySet()));
250 public static File uploadCreatedUpdateParametersEnvFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws Exception {
251 // created env file to upload
252 File pathToEnvParametersFile = prepareEnvParametersFile(heatEnvDetails, directoryPath);
253 ArtifactInfo heatEnvArtifactInfo = new ArtifactInfo(directoryPath, heatEnvDetails.getHeatEnvLabel() + ".env", "heatEnvDesc", heatEnvDetails.getHeatEnvLabel(), heatEnvDetails.getHeatEnvArtifactType());
254 ArtifactUIUtils.fillAndAddNewEnvArtifactParameters(heatEnvArtifactInfo, CompositionPage.artifactPopup());
255 return pathToEnvParametersFile;
258 public static File prepareEnvParametersFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws IOException {
259 File pathToEnvParametersFile = FileHandling.createEmptyFile(directoryPath + heatEnvDetails.getHeatEnvLabel() + ".env");
261 FileHandling.writeToFile(pathToEnvParametersFile, "parameters:", 0);
262 for (HeatParameterDataDefinition paramDefinition : heatEnvDetails.getHeatParameterDefinition()) {
263 Object data = getDataToWrite(paramDefinition);
264 FileHandling.writeToFile(pathToEnvParametersFile, data, 2);
267 return pathToEnvParametersFile;
270 public static Object getDataToWrite(HeatParameterDataDefinition paramDefinition) {
272 switch (paramDefinition.getType()) {
274 String text = "\"string\"";
275 data = getFormatedData(paramDefinition.getName(), text);
278 data = getFormatedData(paramDefinition.getName(), 666);
281 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
282 data = getFormatedData(paramDefinition.getName(), jsonText);
285 if (paramDefinition.getCurrentValue().equals("true")) {
286 data = getFormatedData(paramDefinition.getName(), false);
288 data = getFormatedData(paramDefinition.getName(), true);
291 case "comma_delimited_list":
292 String commaDelimitedListText = "127.0.0.10, 127.0.0.15, 127.0.0.20";
293 data = getFormatedData(paramDefinition.getName(), commaDelimitedListText);
302 public static Map<String, Object> getDataToWriteInUI(List<HeatParameterDataDefinition> paramDefinitionFromGetResourceResponse) {
303 Map<String, Object> newValuesToUpdateInUI = new HashMap<>();
304 for (HeatParameterDataDefinition param : paramDefinitionFromGetResourceResponse) {
305 switch (param.getType()) {
308 String text = "string";
309 newValuesToUpdateInUI.put(param.getName(), text);
312 newValuesToUpdateInUI.put(param.getName(), 666);
315 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
316 newValuesToUpdateInUI.put(param.getName(), jsonText);
319 if (param.getCurrentValue().equals(true)) {
320 newValuesToUpdateInUI.put(param.getName(), false);
322 newValuesToUpdateInUI.put(param.getName(), true);
325 case "comma_delimited_list":
326 String commaDelimitedListText = "127.0.0.10, 127.0.0.15, 127.0.0.20";
327 newValuesToUpdateInUI.put(param.getName(), commaDelimitedListText);
335 return newValuesToUpdateInUI;
338 public static Object getValue(HeatParameterDataDefinition param) {
339 String type = param.getType();
340 Object result = null;
343 result = param.getCurrentValue();
346 result = new Integer(param.getCurrentValue());
349 result = param.getCurrentValue();
352 result = new Boolean(param.getCurrentValue());
354 case "comma_delimited_list":
355 result = param.getCurrentValue();
363 public static Object getFormatedData(String name, Object text) {
364 return name + ": " + text;