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.onap.sdc.frontend.ci.tests.utilities;
23 import com.aventstack.extentreports.Status;
24 import org.apache.commons.lang3.tuple.ImmutablePair;
25 import org.json.simple.JSONArray;
26 import org.json.simple.JSONObject;
27 import org.json.simple.JSONValue;
28 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
29 import org.onap.sdc.frontend.ci.tests.pages.GeneralPageElements;
30 import org.openecomp.sdc.be.model.User;
31 import org.onap.sdc.frontend.ci.tests.datatypes.CreateAndImportButtonsEnum;
32 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
33 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.Dashboard;
34 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
35 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
36 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
37 import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
38 import org.openqa.selenium.By;
39 import org.openqa.selenium.ElementNotVisibleException;
40 import org.openqa.selenium.WebDriver;
41 import org.openqa.selenium.WebElement;
42 import org.openqa.selenium.support.ui.ExpectedConditions;
43 import org.openqa.selenium.support.ui.Select;
44 import org.openqa.selenium.support.ui.WebDriverWait;
47 import java.util.List;
48 import java.util.Random;
50 public final class ResourceUIUtils {
51 public static final String RESOURCE_NAME_PREFIX = "ResourceCDTest-";
52 protected static final boolean IS_BEFORE_TEST = true;
53 public static final String INITIAL_VERSION = "0.1";
54 public static final String ICON_RESOURCE_NAME = "call_controll";
55 protected static final String UPDATED_RESOURCE_ICON_NAME = "objectStorage";
56 private static final int BASIC_TIMEOUT = 10 * 60;
58 private ResourceUIUtils() {
61 private static WebDriver driver = GeneralUIUtils.getDriver();
63 // click and upload tosca file //**to be changed.
64 public static void importFileWithSendKey(String filePath, String fileName, CreateAndImportButtonsEnum type)
66 WebElement importButton = HomeUtils.createAndImportButtons(type, driver).findElement(By.tagName("input"));
67 importButton.sendKeys(filePath + fileName);
70 public static String defineUserId(String userId) {
72 WebElement resourceUserIdTextbox = ResourceGeneralPage.getContactIdField();
73 resourceUserIdTextbox.clear();
74 resourceUserIdTextbox.sendKeys(userId);
78 static String definePropertyName(String name) {
80 WebElement nameProperty = GeneralUIUtils.getDriver().findElement(By.name("propertyName"));
81 nameProperty.sendKeys(name);
85 public static void selectRandomResourceIcon() throws Exception {
86 final int webDriverWaitingTimeout = 10;
87 GeneralUIUtils.moveToStep(StepsEnum.ICON);
88 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), webDriverWaitingTimeout);
89 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
90 List<WebElement> iconElement = GeneralUIUtils.getDriver()
91 .findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
92 iconElement.get(0).click();
95 static void defineDefaultValueByType(String value) {
97 WebElement valueString = GeneralUIUtils.getDriver().findElement(By.name("value"));
99 valueString.sendKeys(value);
102 static void defineBoolenDefaultValue(String value) {
104 WebElement elementBoolean = GeneralUIUtils.getDriver().findElement(By.name("value"));
105 Select se = new Select(elementBoolean);
106 se.selectByValue(value);
109 public static void fillResourceGeneralInformationPage(ResourceReqDetails resource, User user, boolean isNewResource) {
111 ResourceGeneralPage.defineName(resource.getName());
112 ResourceGeneralPage.defineDescription(resource.getDescription());
113 ResourceGeneralPage.defineCategory(resource.getCategories().get(0).getSubcategories().get(0).getName());
114 ResourceGeneralPage.defineVendorName(resource.getVendorName());
115 ResourceGeneralPage.defineVendorRelease(resource.getVendorRelease());
117 ResourceGeneralPage.defineTagsList(resource, new String[]{"This-is-tag", "another-tag", "Test-automation-tag"});
119 ResourceGeneralPage.defineTagsList(resource, new String[]{"one-more-tag"});
121 } catch (Exception e) {
122 throw new RuntimeException(e);
126 public static void fillMaxValueResourceGeneralInformationPage(ResourceReqDetails resource) {
127 final int stringPatternLength = 5000;
128 String stringPattern = "ABCDabcd123456";
129 GeneralUIUtils.addStringtoClipboard(buildStringFromPattern(stringPattern, stringPatternLength));
130 ResourceGeneralPage.defineNameWithPaste();
131 ResourceGeneralPage.defineDescriptionWithPaste();
132 ResourceGeneralPage.defineVendorNameWithPaste();
133 ResourceGeneralPage.defineVendorReleaseWithPaste();
134 ResourceGeneralPage.defineTagsListWithPaste();
135 GeneralUIUtils.waitForAngular();
138 public static String buildStringFromPattern(String stringPattern, int stringLength) {
139 char[] chars = stringPattern.toCharArray();
140 StringBuilder sb = new StringBuilder();
141 Random random = new Random();
142 for (int i = 0; i < stringLength; i++) {
143 char c = chars[random.nextInt(chars.length)];
146 return sb.toString();
150 * @deprecated Use {@link #createVF(ResourceReqDetails, User)} instead
152 public static void createResource(ResourceReqDetails resource, User user) throws Exception {
153 createVF(resource, user);
156 public static void createVF(ResourceReqDetails resource, User user) {
157 ExtentTestActions.log(Status.INFO, "Going to create a new VF.");
158 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_VF);
161 private static void createResource(ResourceReqDetails resource, User user, DataTestIdEnum.Dashboard button) {
162 WebElement addVFButton;
164 GeneralUIUtils.ultimateWait();
166 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
167 addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
168 } catch (Exception e) {
169 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resource.getName());
170 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
171 SetupCDTest.getExtendTest().log(Status.WARNING, "Add button is not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
173 addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
176 GeneralUIUtils.ultimateWait();
177 } catch (Exception e) {
178 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on ADD button, retrying ... "));
179 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
180 GeneralUIUtils.ultimateWait();
181 GeneralUIUtils.getWebElementByTestID(button.getValue()).click();
182 GeneralUIUtils.ultimateWait();
184 fillResourceGeneralInformationPage(resource, user, true);
185 resource.setVersion("0.1");
186 GeneralPageElements.clickCreateButton();
189 public static void updateResource(ResourceReqDetails resource, User user) {
190 ResourceGeneralPage.defineContactId(resource.getContactId());
191 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating General screen fields ..."));
192 fillResourceGeneralInformationPage(resource, user, false);
193 ResourceGeneralPage.clickUpdateButton();
197 * Click on HTML element.
202 public static void getWebElementByTestID(String dataTestId) throws Exception {
203 final int webDriverWaitingTimeout = 20;
204 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), webDriverWaitingTimeout);
205 WebElement element = wait
206 .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
208 // wait.until(ExpectedConditions.elemetto)
209 // WebElement serviceButton =
210 // GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
211 // + dataTestId + "']"));
213 // serviceButton.click();
226 public static void importVfc(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
228 GeneralUIUtils.ultimateWait();
229 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VFC resource ", resourceMetaData.getName()));
230 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
231 GeneralUIUtils.ultimateWait();
232 // Insert file to the browse dialog
233 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
234 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
235 if (!buttonVFC.isDisplayed()) {
236 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
237 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
238 SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
241 fileInputElement.sendKeys(filePath + fileName);
242 } catch (ElementNotVisibleException e) {
243 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
245 fileInputElement.sendKeys(filePath + fileName);
247 // Fill the general page fields.
248 GeneralUIUtils.ultimateWait();
249 fillResourceGeneralInformationPage(resourceMetaData, user, true);
250 GeneralPageElements.clickCreateButton();
253 public static void importVfcNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
255 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
256 // Insert file to the browse dialog
257 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
258 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
259 if (!buttonVFC.isDisplayed()) {
260 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
261 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
262 SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
265 fileInputElement.sendKeys(filePath + fileName);
266 } catch (ElementNotVisibleException e) {
267 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
269 fileInputElement.sendKeys(filePath + fileName);
271 // Fill the general page fields.
272 GeneralUIUtils.waitForLoader();
273 fillResourceGeneralInformationPage(resourceMetaData, user, true);
277 public static void importVfFromCsar(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
279 GeneralUIUtils.ultimateWait();
280 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s", resourceMetaData.getName()));
281 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
282 GeneralUIUtils.ultimateWait();
283 // Insert file to the browse dialog
284 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
285 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
286 if (!buttonDCAE.isDisplayed()) {
287 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
288 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
289 SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
292 fileInputElement.sendKeys(filePath + fileName);
293 } catch (ElementNotVisibleException e) {
294 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
296 fileInputElement.sendKeys(filePath + fileName);
298 // Fill the general page fields.
299 GeneralUIUtils.ultimateWait();
300 fillResourceGeneralInformationPage(resourceMetaData, user, true);
301 GeneralPageElements.clickCreateButton(BASIC_TIMEOUT);
302 //GeneralUIUtils.ultimateWait(); "don't change import of csar can take longer then 3 minutes"
303 GeneralUIUtils.waitForLoader(BASIC_TIMEOUT);
306 public static void importVfFromCsarNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
308 GeneralUIUtils.ultimateWait();
309 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s, Create button will not be clicked", resourceMetaData.getName()));
310 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
311 GeneralUIUtils.ultimateWait();
312 // Insert file to the browse dialog
313 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
314 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
315 if (!buttonDCAE.isDisplayed()) {
316 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
317 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
318 SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
321 fileInputElement.sendKeys(filePath + fileName);
322 } catch (ElementNotVisibleException e) {
323 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
325 fileInputElement.sendKeys(filePath + fileName);
327 // Fill the general page fields.
328 GeneralUIUtils.ultimateWait();
329 fillResourceGeneralInformationPage(resourceMetaData, user, true);
330 GeneralUIUtils.waitForLoader(BASIC_TIMEOUT);
333 public static void updateVfWithCsar(String filePath, String fileName) {
334 ExtentTestActions.log(Status.INFO, "Updating VF with updated CSAR file named " + fileName);
335 WebElement browseWebElement = GeneralUIUtils.getInputElement(DataTestIdEnum.GeneralElementsEnum.UPLOAD_FILE_INPUT.getValue());
336 browseWebElement.sendKeys(filePath + fileName);
337 GeneralUIUtils.ultimateWait();
338 GeneralPageElements.clickUpdateButton();
339 GeneralUIUtils.waitForLoader();
340 ExtentTestActions.log(Status.INFO, "VF is updated.");
343 private static void showButtons() {
344 String parentElementClassAttribute = "sdc-dashboard-import-element-container";
345 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
346 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
347 GeneralUIUtils.ultimateWait();
348 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
351 private static void showButtonsADD() {
353 GeneralUIUtils.ultimateWait();
354 String parentElementClassAttribute = "sdc-dashboard-create-element-container";
355 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
356 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
357 GeneralUIUtils.ultimateWait();
358 } catch (Exception e) {
359 GeneralUIUtils.ultimateWait();
360 String parentElementClassAttribute = "sdc-dashboard-create-element-container";
361 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
362 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
363 GeneralUIUtils.ultimateWait();
365 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
368 public static void clickOnElementByText(String textToClick, String customizationFoLog) {
369 String customizationFoLogLocal = customizationFoLog != null ? customizationFoLog : "";
370 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s %s", textToClick, customizationFoLogLocal));
371 GeneralUIUtils.clickOnElementByText(textToClick);
374 public static void createPNF(ResourceReqDetails resource, User user) throws Exception {
375 ExtentTestActions.log(Status.INFO, "Going to create a new PNF");
376 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_PNF);
379 public static void createCR(ResourceReqDetails resource, User user) throws Exception {
380 ExtentTestActions.log(Status.INFO, "Going to create a new CR");
381 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_CR);
384 public static ImmutablePair<String, String> getFirstRIPos(ResourceReqDetails createResourceInUI, User user) {
385 String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
386 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
387 String xPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
389 String yPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
391 return new ImmutablePair<String, String>(xPosPostDrag, yPosPostDrag);