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 static org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest.getExtendTest;
24 import static org.testng.AssertJUnit.assertTrue;
26 import com.aventstack.extentreports.Status;
27 import java.awt.Toolkit;
28 import java.awt.datatransfer.Clipboard;
29 import java.awt.datatransfer.StringSelection;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
35 import java.util.UUID;
36 import java.util.concurrent.TimeUnit;
37 import java.util.function.Supplier;
38 import org.apache.commons.io.FileUtils;
39 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
40 import org.openecomp.sdc.ci.tests.exception.GeneralUiRuntimeException;
41 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
42 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
43 import org.openecomp.sdc.ci.tests.pages.HomePage;
44 import org.openecomp.sdc.ci.tests.utils.Utils;
45 import org.openqa.selenium.By;
46 import org.openqa.selenium.JavascriptExecutor;
47 import org.openqa.selenium.Keys;
48 import org.openqa.selenium.NoSuchElementException;
49 import org.openqa.selenium.OutputType;
50 import org.openqa.selenium.TakesScreenshot;
51 import org.openqa.selenium.WebDriver;
52 import org.openqa.selenium.WebElement;
53 import org.openqa.selenium.firefox.FirefoxDriver;
54 import org.openqa.selenium.interactions.Actions;
55 import org.openqa.selenium.support.ui.ExpectedConditions;
56 import org.openqa.selenium.support.ui.Select;
57 import org.openqa.selenium.support.ui.WebDriverWait;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
62 public final class GeneralUIUtils {
64 private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUIUtils.class);
66 private static final String TEST_ID_XPATH = "//*[@data-test-id='%1$s' or @data-tests-id='%1$s']";
67 private static final String TEST_ID_CHILD_XPATH = "//*[@data-tests-id='%s']//*";
68 private static final String TEST_ID_ATTRIBUTE_NAME = "data-tests-id";
69 private static final String COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW = "color: yellow; border: 4px solid yellow;";
71 private static final int TIME_OUT = (int) (60 * 1.5);
72 private static final int WEB_DRIVER_WAIT_TIME_OUT = 10;
73 private static final int SLEEP_DURATION = 1000;
74 private static final int MAX_WAITING_PERIOD = 10 * 1000;
75 private static final int NAP_PERIOD = 100;
76 private static final int DURATION_FORMATIN = 60;
78 private GeneralUIUtils () {
82 public static int getTimeOut() {
86 public static WebDriver getDriver() {
87 return DriverFactory.getDriver();
90 public static List<WebElement> getElementsByLocator(By by) {
91 return getDriver().findElements(by);
94 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
95 if (screenshotFilename == null) {
96 if (testName != null) {
97 screenshotFilename = testName;
99 screenshotFilename = UUID.randomUUID().toString();
103 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
104 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
105 new File(dir).mkdirs();
106 FileUtils.copyFile(scrFile, filePath);
108 } catch (IOException e1) {
109 e1.printStackTrace();
114 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException {
115 return takeScreenshot(screenshotFilename, dir, null);
118 public static WebElement getWebElementByTestID(String dataTestId) {
119 return getWebElementByTestID(dataTestId, TIME_OUT);
122 public static WebElement getWebElementByTestID(final String dataTestId, final int timeout) {
124 final WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
125 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(TEST_ID_XPATH, dataTestId))));
127 catch (final Exception e) {
129 .debug(String.format("Element with attribute %s=%s not found", TEST_ID_ATTRIBUTE_NAME, dataTestId), e);
134 public static boolean isWebElementExistByTestId(String dataTestId) {
135 return getDriver().findElements(By.xpath(String.format(TEST_ID_XPATH, dataTestId))).size() != 0;
138 public static boolean isWebElementExistByClass(String className) {
139 return getDriver().findElements(By.className(className)).size() != 0;
142 public static WebElement getInputElement(String dataTestId) {
145 return getDriver().findElement(By.xpath(String.format(TEST_ID_XPATH, dataTestId)));
146 } catch (Exception e) {
151 public static List<WebElement> getInputElements(String dataTestId) {
153 return getDriver().findElements(By.xpath(String.format(TEST_ID_XPATH, dataTestId)));
157 public static WebElement getWebElementBy(By by) {
158 return getWebElementBy(by, TIME_OUT);
161 public static WebElement getWebElementBy(By by, int timeOut) {
162 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
163 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
166 public static WebElement getWebElementByPresence(By by, int timeOut) {
167 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
168 return wait.until(ExpectedConditions.presenceOfElementLocated(by));
171 public static List<String> getWebElementListText(List<WebElement> elements) {
172 List<String> Text = new ArrayList<>();
173 for (WebElement webElement : elements) {
174 Text.add(webElement.getText());
179 public static List<WebElement> getWebElementsListBy(By by) {
180 return getWebElementsListBy(by, TIME_OUT);
183 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
184 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
185 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
188 public static List<WebElement> getWebElementsListByContainTestID(final String dataTestId) {
190 final WebDriverWait wait = new WebDriverWait(getDriver(), WEB_DRIVER_WAIT_TIME_OUT);
191 final String xpath = String.format("//*[contains(@%s, '%s')]", TEST_ID_ATTRIBUTE_NAME, dataTestId);
192 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpath)));
193 } catch (final Exception e) {
194 final String message = String.format("Could not find element containing the attribute '%s' as '%s'",
195 TEST_ID_ATTRIBUTE_NAME, dataTestId);
196 LOGGER.debug(message, e);
197 return Collections.emptyList();
201 public static List<WebElement> getWebElementsListByContainsClassName(final String containedText) {
202 final WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
203 return wait.until(ExpectedConditions.
204 presenceOfAllElementsLocatedBy(By.xpath(String.format("//*[contains(@class, '%s')]", containedText))));
207 public static WebElement getWebElementByContainsClassName(final String containedText) {
208 return getWebElementBy(By.xpath(String.format("//*[contains(@class, '%s')]", containedText)));
211 public static WebElement getWebElementByClassName(String className) {
212 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
213 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
216 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
217 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
218 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(String.format(TEST_ID_XPATH, dataTestId))));
221 public static List<WebElement> getWebElementsListByClassName(String className) {
222 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
223 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
227 public static Boolean isElementInvisibleByTestId(String dataTestId) {
228 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
230 ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(TEST_ID_XPATH, dataTestId))));
233 public static Boolean isElementVisibleByTestId(String dataTestId) {
235 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
236 return wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath(String.format(TEST_ID_XPATH, dataTestId))))).isDisplayed();
237 } catch (Exception e) {
242 public static void clickOnElementByTestId(String dataTestId) {
244 clickOnElementByTestIdWithoutWait(dataTestId);
246 }catch (Exception e) {
251 public static void clickOnElementByTestIdWithoutWait(final String dataTestId) {
253 final WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
254 wait.until(ExpectedConditions
255 .elementToBeClickable(By.xpath(String.format(TEST_ID_XPATH, dataTestId)))).click();
256 final String message =
257 String.format("Click on element with attribute '%s' value '%s'", TEST_ID_XPATH, dataTestId);
258 getExtendTest().log(Status.INFO, message);
259 } catch (final Exception e) {
260 ExtentTestActions.log(Status.FAIL, dataTestId + " element isn't clickable");
261 ExtentTestActions.log(Status.FAIL, e);
265 public static void clickOnElementByInputTestIdWithoutWait(final String dataTestId) {
266 final WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
267 final String xPath = String.format(TEST_ID_CHILD_XPATH, dataTestId);
268 wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xPath))).click();
271 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
272 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
273 wait.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(TEST_ID_XPATH, dataTestId)))).click();
276 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
277 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
278 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(TEST_ID_XPATH, dataTestId))));
281 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
282 return waitForElementInVisibilityByTestId(dataTestId, TIME_OUT);
285 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
286 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
287 boolean displayed = getDriver().findElements(By.xpath(String.format(TEST_ID_XPATH, dataTestId))).isEmpty();
289 return wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(TEST_ID_XPATH, dataTestId))));
294 public static Boolean waitForElementInVisibilityByTestId(By by) {
295 return waitForElementInVisibilityBy(by, TIME_OUT);
299 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
300 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
301 boolean displayed = getDriver().findElements(by).isEmpty();
303 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
304 sleep(SLEEP_DURATION);
311 public static void setWebElementByTestId(String elemetID, String value) {
312 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
313 resourceDescriptionTextbox.clear();
314 resourceDescriptionTextbox.sendKeys(value);
318 public static WebElement hoverOnAreaByTestId(String areaId) {
319 Actions actions = new Actions(getDriver());
320 WebElement area = getWebElementByTestID(areaId);
321 actions.moveToElement(area).perform();
326 public static WebElement hoverOnAreaByClassName(String className) {
327 Actions actions = new Actions(getDriver());
328 WebElement area = getWebElementByClassName(className);
329 actions.moveToElement(area).perform();
330 GeneralUIUtils.ultimateWait();
334 public static void waitForLoader() {
335 waitForLoader(TIME_OUT);
338 public static void waitForLoader(int timeOut) {
339 final String loaderClass = "tlv-loader";
340 final int sleepDuration = 500;
341 sleep(sleepDuration);
342 LOGGER.debug("Waiting {}s for '.{}'", timeOut, loaderClass);
343 waitForElementInVisibilityBy(By.className(loaderClass), timeOut);
346 public static void findComponentAndClick(final String resourceName) {
347 HomePage.findComponentAndClick(resourceName);
350 public static void windowZoomOut() {
351 final int zoomOutFactor = 3;
352 for (int i = 0; i < zoomOutFactor; i++) {
353 if (getDriver() instanceof FirefoxDriver) {
354 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
359 public static void resetZoom() {
360 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
363 public static void windowZoomOutUltimate() {
368 public static void sleep(int duration) {
370 Thread.sleep(duration);
371 } catch (final InterruptedException e) {
372 Thread.currentThread().interrupt();
373 throw new GeneralUiRuntimeException("The thread was interrupted during a sleep", e);
377 public static void moveToStep(final DataTestIdEnum.StepsEnum stepName) {
378 getExtendTest().log(Status.INFO, String.format("Going to %s page ", stepName.toString()));
379 moveToStep(stepName.getValue());
382 public static void moveToStep(final String dataTestId) {
383 clickOnElementByTestId(dataTestId);
387 public static Select getSelectList(String item, String datatestsid) {
388 Select selectList = new Select(getWebElementByTestID(datatestsid));
390 selectList.selectByVisibleText(item);
395 public static List<WebElement> getElementsByCSS(String cssString) /*throws InterruptedException*/ {
396 GeneralUIUtils.waitForLoader();
397 return getDriver().findElements(By.cssSelector(cssString));
400 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString) {
401 GeneralUIUtils.waitForLoader();
402 return parentElement.findElement(By.cssSelector(cssString));
405 private static WebElement highlightMyElement(WebElement element) {
406 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
407 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
411 public static WebElement getSelectedElementFromDropDown(String dataTestId) {
412 GeneralUIUtils.ultimateWait();
413 return new Select(getDriver().findElement(By.xpath(String.format(TEST_ID_XPATH, dataTestId)))).getFirstSelectedOption();
416 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
417 int maxWaitingPeriodMS = MAX_WAITING_PERIOD;
418 int napPeriodMS = NAP_PERIOD;
419 int sumOfWaiting = 0;
420 List<WebElement> elements;
421 boolean isKeepWaiting = false;
422 while (!isKeepWaiting) {
423 elements = func.get();
424 isKeepWaiting = (expectedElementsCount == elements.size());
426 sumOfWaiting += napPeriodMS;
427 if (sumOfWaiting > maxWaitingPeriodMS) {
434 public static String getActionDuration(Runnable func) {
435 long startTime = System.nanoTime();
437 long estimateTime = System.nanoTime();
438 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
439 return String.format("%02d:%02d", duration / DURATION_FORMATIN, duration % DURATION_FORMATIN);
442 public static WebElement clickOnAreaJS(String areaId) {
443 return clickOnAreaJS(areaId, TIME_OUT);
447 public static WebElement clickOnAreaJS(String areaId, int timeout) {
450 WebElement area = getWebElementByTestID(areaId);
451 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
452 Object executeScript = javascript.executeScript("arguments[0].click();", area, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
453 waitForLoader(timeout);
456 } catch (Exception e) {
463 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
464 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
465 javascript.executeScript("arguments[0].click();", areaId, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
470 public static void clickSomewhereOnPage() {
471 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
474 public static void clickOnElementByText(String textInElement) {
475 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
476 highlightMyElement(wait.until(
477 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
480 public static void clickOnElementByText(String textInElement, int customTimeout) {
481 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
482 highlightMyElement(wait.until(
483 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
486 public static void clickJSOnElementByText(String textInElement) throws Exception {
487 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
488 clickOnAreaJS(wait.until(
489 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
492 public static void waitForAngular() {
493 LOGGER.debug("Waiting for angular");
494 final int webDriverWaitingTime = 90;
495 WebDriverWait wait = new WebDriverWait(getDriver(), webDriverWaitingTime, NAP_PERIOD);
496 wait.until(AdditionalConditions.pageLoadWait());
497 wait.until(AdditionalConditions.angularHasFinishedProcessing());
498 LOGGER.debug("Waiting for angular finished");
501 public static Object getAllElementAttributes(WebElement element) {
502 return ((JavascriptExecutor) getDriver()).executeScript("var s = []; var attrs = arguments[0].attributes; for (var l = 0; l < attrs.length; ++l) { var a = attrs[l]; s.push(a.name + ':' + a.value); } ; return s;", element);
505 public static boolean isElementReadOnly(WebElement element) {
507 highlightMyElement(element).clear();
509 } catch (Exception e) {
514 public static boolean isElementReadOnly(String dataTestId) {
515 return isElementReadOnly(
516 waitForElementVisibilityByTestId(dataTestId));
519 public static boolean isElementDisabled(WebElement element) {
520 return highlightMyElement(element).getAttribute("class").contains("view-mode")
521 || element.getAttribute("class").contains("disabled") || element.getAttribute("disabled") != null;
524 public static boolean isElementDisabled(String dataTestId) {
525 return isElementDisabled(
526 waitForElementVisibilityByTestId(dataTestId));
529 public static void ultimateWait() {
530 long startTime = System.nanoTime();
532 GeneralUIUtils.waitForLoader();
533 GeneralUIUtils.waitForBackLoader();
534 GeneralUIUtils.waitForAngular();
536 long estimateTime = System.nanoTime();
537 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
538 if (duration > TIME_OUT) {
539 getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
543 public static WebElement unhideElement(WebElement element, String attributeValue) {
544 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
545 ((JavascriptExecutor) getDriver()).executeScript(js, element);
549 public static WebElement findByText(String textInElement) {
550 return getDriver().findElement(searchByTextContaining(textInElement));
553 public static By searchByTextContaining(String textInElement) {
554 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
557 public static WebElement getClickableButtonBy(By by, int timout) {
559 WebDriverWait wait = new WebDriverWait(getDriver(), timout);
560 return wait.until(ExpectedConditions.elementToBeClickable(by));
561 } catch (Exception e) {
567 public static WebElement getButtonWithText(String textInButton) {
569 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
570 } catch (Exception e) {
575 public static void closeErrorMessage() {
576 WebElement okWebElement = getButtonWithText("OK");
577 if (okWebElement != null) {
578 okWebElement.click();
583 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
585 return getDriver().findElement(By.cssSelector(cssString));
588 public static String getDataTestIdAttributeValue(WebElement element) {
589 return element.getAttribute(TEST_ID_ATTRIBUTE_NAME);
592 public static String getTextContentAttributeValue(WebElement element) {
593 return element.getAttribute("textContent");
596 public static void clickOnElementByCSS(String cssString) throws Exception {
597 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
598 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
602 public static boolean checkForDisabledAttribute(String dataTestId) {
603 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
604 return elementAttributes.toString().contains("disabled");
607 public static void dragAndDropElementByY(WebElement area, int yOffset) {
608 final int dragAndDropTimeout = 10;
609 Actions actions = new Actions(getDriver());
610 actions.dragAndDropBy(area, dragAndDropTimeout, yOffset).perform();
614 public static void waitForBackLoader() {
615 waitForBackLoader(TIME_OUT);
618 public static void waitForBackLoader(int timeOut) {
620 final String backLoaderClass = "tlv-loader-back";
621 LOGGER.debug("Waiting {}s for '.{}'", timeOut, backLoaderClass);
622 waitForElementInVisibilityBy(By.className(backLoaderClass), timeOut);
625 public static void addStringtoClipboard(String text) {
626 StringSelection selection = new StringSelection(text);
627 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
628 clipboard.setContents(selection, selection);
631 public static boolean checkForDisabledAttributeInHiddenElement(String cssString) {
632 final int numberOfDisableElements = 3;
633 boolean isDisabled = false;
634 for (int i = 0; i < numberOfDisableElements; i++) {
635 Object elementAttributes = getAllElementAttributes(getWebElementByPresence(By.cssSelector(cssString), TIME_OUT));
636 isDisabled = elementAttributes.toString().contains("disabled");
645 public static void selectByValueTextContained(String dataTestsId, String value) {
647 List<WebElement> options = GeneralUIUtils.getWebElementsListBy(By.xpath(String.format("//select[@data-tests-id='%1$s' or @data-test-id='%1$s']//option[contains(@value,'%2$s')]", dataTestsId, value)));
649 boolean matched = false;
650 for (WebElement option : options) {
656 throw new NoSuchElementException("Cannot locate option with value: " + value);
662 public static void setTextInElementByXpath(String xPath, String text) {
663 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
666 webElement.sendKeys(text);
671 public static void clickOnElementByXpath(String xPath) {
672 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
677 public static String getTextValueFromWebElementByXpath(String xpath) {
678 WebElement webElement = getWebElementBy(By.xpath(xpath));
679 return webElement.getAttribute("value");
682 public static List<WebElement> findElementsByXpath(String xPath) {
683 return getDriver().findElements(By.xpath(xPath));
686 public static void clickOnBrowserBackButton() throws Exception {
687 getExtendTest().log(Status.INFO, "Going to press on back browser button.");
688 getDriver().navigate().back();
692 public static String copyCurrentURL() throws Exception {
693 getExtendTest().log(Status.INFO, "Copying current URL");
694 return getDriver().getCurrentUrl();
697 public static void navigateToURL(String url) throws Exception {
698 getExtendTest().log(Status.INFO, "Navigating to URL " + url);
699 getDriver().navigate().to(url);
702 public static void refreshWebpage() throws Exception {
703 getExtendTest().log(Status.INFO, "Refreshing Webpage");
704 getDriver().navigate().refresh();
708 public static Object getElementPositionOnCanvas(String elementName) {
709 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
710 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
711 + "var nPos = n.renderedPosition();\n"
712 + "return JSON.stringify({\n"
716 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
719 public static Object getElementGreenDotPositionOnCanvas(String elementName) {
720 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
721 + "var cyZoom = cy.zoom();\n"
722 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
723 + "var nPos = n.renderedPosition();\n"
724 + "var nData = n.data();\n"
725 + "var nImgSize = nData.imgWidth;\n"
726 + "var shiftSize = (nImgSize-18)*cyZoom/2;\n"
727 + "return JSON.stringify({\n"
728 + "\tx: nPos.x + shiftSize,\n"
729 + "\ty: nPos.y - shiftSize\n"
731 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
734 public static Long getAndValidateActionDuration(Runnable action, int regularTestRunTime) {
735 Long actualTestRunTime = null;
737 actualTestRunTime = Utils.getActionDuration(() -> {
740 } catch (Throwable throwable) {
741 throwable.printStackTrace();
744 } catch (Exception e) {
747 final double factor = 1.5;
749 assertTrue("Expected test run time should be less than " + regularTestRunTime * factor + ", "
750 + "actual time is " + actualTestRunTime, regularTestRunTime * factor > actualTestRunTime);
751 //SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is " + actualTestRunTime + " seconds");
752 return actualTestRunTime;