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.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.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.Dashboard;
32 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
34 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
35 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
36 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
37 import org.openecomp.sdc.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";
57 private ResourceUIUtils() {
60 static WebDriver driver = GeneralUIUtils.getDriver();
62 // click and upload tosca file //**to be changed.
63 public static void importFileWithSendKey(String FilePath, String FileName, CreateAndImportButtonsEnum type)
65 WebElement importButton = HomeUtils.createAndImportButtons(type, driver).findElement(By.tagName("input"));
66 importButton.sendKeys(FilePath + FileName);
69 public static String defineUserId(String userId) {
71 WebElement resourceUserIdTextbox = ResourceGeneralPage.getContactIdField();
72 resourceUserIdTextbox.clear();
73 resourceUserIdTextbox.sendKeys(userId);
77 public static String definePropertyName(String name) {
79 WebElement nameProperty = GeneralUIUtils.getDriver().findElement(By.name("propertyName"));
80 nameProperty.sendKeys(name);
84 public static void selectRandomResourceIcon() throws Exception {
85 GeneralUIUtils.moveToStep(StepsEnum.ICON);
86 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 4);
87 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
88 List<WebElement> iconElement = GeneralUIUtils.getDriver()
89 .findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
90 iconElement.get(0).click();
93 public static void defineDefaultValueByType(String Value) {
95 WebElement valueString = GeneralUIUtils.getDriver().findElement(By.name("value"));
97 valueString.sendKeys(Value);
100 public static void defineBoolenDefaultValue(String Value) {
102 WebElement elementBoolean = GeneralUIUtils.getDriver().findElement(By.name("value"));
103 Select se = new Select(elementBoolean);
104 se.selectByValue(Value);
107 public static void fillResourceGeneralInformationPage(ResourceReqDetails resource, User user, boolean isNewResource) {
109 ResourceGeneralPage.defineName(resource.getName());
110 ResourceGeneralPage.defineDescription(resource.getDescription());
111 ResourceGeneralPage.defineCategory(resource.getCategories().get(0).getSubcategories().get(0).getName());
112 ResourceGeneralPage.defineVendorName(resource.getVendorName());
113 ResourceGeneralPage.defineVendorRelease(resource.getVendorRelease());
115 ResourceGeneralPage.defineTagsList(resource, new String[] { "This-is-tag", "another-tag", "Test-automation-tag" });
118 ResourceGeneralPage.defineTagsList(resource, new String[] { "one-more-tag" });
120 } catch (Exception e) {
121 throw new RuntimeException(e);
125 public static void fillMaxValueResourceGeneralInformationPage(ResourceReqDetails resource) {
126 String stringPattern = "ABCDabcd123456";
127 GeneralUIUtils.addStringtoClipboard(buildStringFromPattern(stringPattern, 5000));
128 ResourceGeneralPage.defineNameWithPaste();
129 ResourceGeneralPage.defineDescriptionWithPaste();
130 ResourceGeneralPage.defineVendorNameWithPaste();
131 ResourceGeneralPage.defineVendorReleaseWithPaste();
132 ResourceGeneralPage.defineTagsListWithPaste();
133 GeneralUIUtils.waitForAngular();
136 public static String buildStringFromPattern(String stringPattern, int stringLength){
137 char[] chars = stringPattern.toCharArray();
138 StringBuilder sb = new StringBuilder();
139 Random random = new Random();
140 for (int i = 0; i < stringLength; i++) {
141 char c = chars[random.nextInt(chars.length)];
144 return sb.toString();
148 * @deprecated Use {@link #createVF(ResourceReqDetails,User)} instead
150 public static void createResource(ResourceReqDetails resource, User user) throws Exception {
151 createVF(resource, user);
154 public static void createVF(ResourceReqDetails resource, User user) throws Exception {
155 ExtentTestActions.log(Status.INFO, "Going to create a new VF.");
156 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_VF);
159 public static void createResource(ResourceReqDetails resource, User user, DataTestIdEnum.Dashboard button) {
160 WebElement addVFButton;
162 GeneralUIUtils.ultimateWait();
164 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
165 addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
168 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resource.getName());
169 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
170 SetupCDTest.getExtendTest().log(Status.WARNING, "Add button is not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
172 addVFButton = GeneralUIUtils.getWebElementByTestID(button.getValue());
175 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 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 20);
204 WebElement element = wait
205 .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
207 // wait.until(ExpectedConditions.elemetto)
208 // WebElement serviceButton =
209 // GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
210 // + dataTestId + "']"));
212 // serviceButton.click();
225 public static void importVfc(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
227 GeneralUIUtils.ultimateWait();
228 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VFC resource ", resourceMetaData.getName()));
229 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
230 GeneralUIUtils.ultimateWait();
231 // Insert file to the browse dialog
232 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
233 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
234 if (!buttonVFC.isDisplayed()){
235 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
236 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
237 SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
240 fileInputElement.sendKeys(filePath + fileName);
241 } catch (ElementNotVisibleException e) {
242 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
244 fileInputElement.sendKeys(filePath + fileName);
246 // Fill the general page fields.
247 GeneralUIUtils.ultimateWait();
248 fillResourceGeneralInformationPage(resourceMetaData, user, true);
249 GeneralPageElements.clickCreateButton();
252 public static void importVfcNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
254 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
255 // Insert file to the browse dialog
256 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
257 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
258 if (!buttonVFC.isDisplayed()){
259 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
260 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
261 SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
264 fileInputElement.sendKeys(filePath + fileName);
265 } catch (ElementNotVisibleException e) {
266 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
268 fileInputElement.sendKeys(filePath + fileName);
270 // Fill the general page fields.
271 GeneralUIUtils.waitForLoader();
272 fillResourceGeneralInformationPage(resourceMetaData, user, true);
276 public static void importVfFromCsar(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
278 GeneralUIUtils.ultimateWait();
279 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s", resourceMetaData.getName()));
280 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
281 GeneralUIUtils.ultimateWait();
282 // Insert file to the browse dialog
283 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
284 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
285 if (!buttonDCAE.isDisplayed()){
286 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
287 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
288 SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
291 fileInputElement.sendKeys(filePath + fileName);
292 } catch (ElementNotVisibleException e) {
293 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
295 fileInputElement.sendKeys(filePath + fileName);
297 // Fill the general page fields.
298 GeneralUIUtils.ultimateWait();
299 fillResourceGeneralInformationPage(resourceMetaData, user, true);
300 GeneralPageElements.clickCreateButton(10*60);
301 // GeneralUIUtils.ultimateWait(); "don't change import of csar can take longer then 3 minutes"
302 GeneralUIUtils.waitForLoader(10*60);
305 public static void importVfFromCsarNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
307 GeneralUIUtils.ultimateWait();
308 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s, Create button will not be clicked", resourceMetaData.getName()));
309 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
310 GeneralUIUtils.ultimateWait();
311 // Insert file to the browse dialog
312 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
313 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
314 if (!buttonDCAE.isDisplayed()){
315 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
316 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
317 SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
320 fileInputElement.sendKeys(filePath + fileName);
321 } catch (ElementNotVisibleException e) {
322 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
324 fileInputElement.sendKeys(filePath + fileName);
326 // Fill the general page fields.
327 GeneralUIUtils.ultimateWait();
328 fillResourceGeneralInformationPage(resourceMetaData, user, true);
329 GeneralUIUtils.waitForLoader(10*60);
332 public static void updateVfWithCsar(String filePath, String fileName) {
333 ExtentTestActions.log(Status.INFO, "Updating VF with updated CSAR file named " + fileName);
334 WebElement browseWebElement = GeneralUIUtils.getInputElement(DataTestIdEnum.GeneralElementsEnum.UPLOAD_FILE_INPUT.getValue());
335 browseWebElement.sendKeys(filePath + fileName);
336 GeneralUIUtils.ultimateWait();
337 GeneralPageElements.clickUpdateButton();
338 GeneralUIUtils.waitForLoader();
339 ExtentTestActions.log(Status.INFO, "VF is updated.");
342 public static void showButtons(){
343 String parentElementClassAttribute = "sdc-dashboard-import-element-container";
344 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
345 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
346 GeneralUIUtils.ultimateWait();
347 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
350 public static void showButtonsADD(){
352 GeneralUIUtils.ultimateWait();
353 String parentElementClassAttribute = "sdc-dashboard-create-element-container";
354 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
355 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
356 GeneralUIUtils.ultimateWait();
357 } catch (Exception e ){
358 GeneralUIUtils.ultimateWait();
359 String parentElementClassAttribute = "sdc-dashboard-create-element-container";
360 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
361 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
362 GeneralUIUtils.ultimateWait();
364 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
367 public static void clickOnElementByText(String textToClick, String customizationFoLog){
368 String customizationFoLogLocal = customizationFoLog != null ? customizationFoLog : "";
369 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s %s", textToClick, customizationFoLogLocal));
370 GeneralUIUtils.clickOnElementByText(textToClick);
373 public static void createPNF(ResourceReqDetails resource, User user) throws Exception {
374 ExtentTestActions.log(Status.INFO, "Going to create a new PNF");
375 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_PNF);
378 public static void createCR(ResourceReqDetails resource, User user) throws Exception {
379 ExtentTestActions.log(Status.INFO, "Going to create a new CR");
380 createResource(resource, user, DataTestIdEnum.Dashboard.BUTTON_ADD_CR);
383 public static ImmutablePair<String, String> getFirstRIPos(ResourceReqDetails createResourceInUI, User user) {
384 String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
385 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
386 String xPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
388 String yPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
390 return new ImmutablePair<String, String>(xPosPostDrag, yPosPostDrag);