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.io.FileUtils;
25 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
26 import org.openecomp.sdc.ci.tests.exception.GeneralUiRuntimeException;
27 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
28 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
29 import org.openecomp.sdc.ci.tests.pages.HomePage;
30 import org.openecomp.sdc.ci.tests.utils.Utils;
31 import org.openqa.selenium.By;
32 import org.openqa.selenium.JavascriptExecutor;
33 import org.openqa.selenium.Keys;
34 import org.openqa.selenium.NoSuchElementException;
35 import org.openqa.selenium.OutputType;
36 import org.openqa.selenium.TakesScreenshot;
37 import org.openqa.selenium.WebDriver;
38 import org.openqa.selenium.WebElement;
39 import org.openqa.selenium.firefox.FirefoxDriver;
40 import org.openqa.selenium.interactions.Actions;
41 import org.openqa.selenium.support.ui.ExpectedConditions;
42 import org.openqa.selenium.support.ui.Select;
43 import org.openqa.selenium.support.ui.WebDriverWait;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 import java.awt.datatransfer.Clipboard;
49 import java.awt.datatransfer.StringSelection;
51 import java.io.IOException;
52 import java.util.ArrayList;
53 import java.util.List;
54 import java.util.UUID;
55 import java.util.concurrent.TimeUnit;
56 import java.util.function.Supplier;
58 import static org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest.getExtendTest;
59 import static org.testng.AssertJUnit.assertTrue;
62 public final class GeneralUIUtils {
64 private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUIUtils.class);
66 private static final String DATA_TESTS_ID = "//*[@data-tests-id='";
67 private static final String COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW = "color: yellow; border: 4px solid yellow;";
69 private static final int TIME_OUT = (int) (60 * 1.5);
70 private static final int WEB_DRIVER_WAIT_TIME_OUT = 10;
71 private static final int SLEEP_DURATION = 1000;
72 private static final int MAX_WAITING_PERIOD = 10 * 1000;
73 private static final int NAP_PERIOD = 100;
74 private static final int DURATION_FORMATIN = 60;
76 private GeneralUIUtils () {
80 public static int getTimeOut() {
84 public static WebDriver getDriver() {
85 return DriverFactory.getDriver();
88 public static List<WebElement> getElementsByLocator(By by) {
89 return getDriver().findElements(by);
92 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
93 if (screenshotFilename == null) {
94 if (testName != null) {
95 screenshotFilename = testName;
97 screenshotFilename = UUID.randomUUID().toString();
101 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
102 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
103 new File(dir).mkdirs();
104 FileUtils.copyFile(scrFile, filePath);
106 } catch (IOException e1) {
107 e1.printStackTrace();
112 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException {
113 return takeScreenshot(screenshotFilename, dir, null);
116 public static WebElement getWebElementByTestID(String dataTestId) {
117 return getWebElementByTestID(dataTestId, TIME_OUT);
120 public static WebElement getWebElementByTestID(final String dataTestId, final int timeout) {
122 final WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
123 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))));
125 catch (Exception e) {
126 System.out.println("Element with dataTestId name: "+dataTestId+" not found");
131 public static boolean isWebElementExistByTestId(String dataTestId) {
132 return getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))).size() != 0;
135 public static boolean isWebElementExistByClass(String className) {
136 return getDriver().findElements(By.className(className)).size() != 0;
139 public static WebElement getInputElement(String dataTestId) {
142 return getDriver().findElement(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']")));
143 } catch (Exception e) {
148 public static List<WebElement> getInputElements(String dataTestId) {
150 return getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']")));
154 public static WebElement getWebElementBy(By by) {
155 return getWebElementBy(by, TIME_OUT);
158 public static WebElement getWebElementBy(By by, int timeOut) {
159 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
160 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
163 public static WebElement getWebElementByPresence(By by, int timeOut) {
164 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
165 return wait.until(ExpectedConditions.presenceOfElementLocated(by));
168 public static List<String> getWebElementListText(List<WebElement> elements) {
169 List<String> Text = new ArrayList<>();
170 for (WebElement webElement : elements) {
171 Text.add(webElement.getText());
176 public static List<WebElement> getWebElementsListBy(By by) {
177 return getWebElementsListBy(by, TIME_OUT);
180 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
181 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
182 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
185 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
187 WebDriverWait wait = new WebDriverWait(getDriver(), WEB_DRIVER_WAIT_TIME_OUT);
188 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(String.format("//*[contains(@data-tests-id, '", dataTestId, "')]"))));
189 } catch (Exception e) {
190 return new ArrayList<WebElement>();
194 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
195 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
196 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '" + containedText + "')]")));
199 public static WebElement getWebElementByContainsClassName(String containedText) {
200 return getWebElementBy(By.xpath("//*[contains(@class, '" + containedText + "')]"));
203 public static WebElement getWebElementByClassName(String className) {
204 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
205 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
208 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
209 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
210 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))));
213 public static List<WebElement> getWebElementsListByClassName(String className) {
214 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
215 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
219 public static Boolean isElementInvisibleByTestId(String dataTestId) {
220 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
222 ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))));
225 public static Boolean isElementVisibleByTestId(String dataTestId) {
227 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
228 return wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))))).isDisplayed();
229 } catch (Exception e) {
234 public static void clickOnElementByTestId(String dataTestId) {
236 clickOnElementByTestIdWithoutWait(dataTestId);
238 }catch (Exception e) {
243 public static boolean tryToclickOnElementByTestId(String dataTestId, int timeOut) {
245 clickOnElementByTestId(dataTestId, timeOut);
248 } catch (Exception e) {
254 public static void clickOnElementByTestIdWithoutWait(String dataTestId) {
255 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
257 wait.until(ExpectedConditions
258 .elementToBeClickable(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']")))).click();
259 getExtendTest().log(Status.INFO, String.format("Click on element ", DATA_TESTS_ID, dataTestId, "']"));
260 } catch (Exception e) {
261 ExtentTestActions.log(Status.FAIL, dataTestId + " element isn't clickable");
262 ExtentTestActions.log(Status.FAIL, e);
266 public static void clickOnElementByInputTestIdWithoutWait(String dataTestId) {
267 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
268 wait.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']//*")))).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(DATA_TESTS_ID, 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(DATA_TESTS_ID, dataTestId, "']"))));
281 public static WebElement waitForElementVisibilityByClass(String className) {
282 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
283 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format("//*[contains(@class, '", className, "')]"))));
286 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
287 return waitForElementInVisibilityByTestId(dataTestId, TIME_OUT);
290 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
291 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
292 boolean displayed = getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']"))).isEmpty();
294 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "'])"))));
300 public static Boolean waitForElementInVisibilityByTestId(By by) {
301 return waitForElementInVisibilityBy(by, TIME_OUT);
305 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
306 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
307 boolean displayed = getDriver().findElements(by).isEmpty();
309 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
310 sleep(SLEEP_DURATION);
317 public static void setWebElementByTestId(String elemetID, String value) {
318 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
319 resourceDescriptionTextbox.clear();
320 resourceDescriptionTextbox.sendKeys(value);
324 public static WebElement hoverOnAreaByTestId(String areaId) {
325 Actions actions = new Actions(getDriver());
326 WebElement area = getWebElementByTestID(areaId);
327 actions.moveToElement(area).perform();
332 public static WebElement hoverOnAreaByClassName(String className) {
333 Actions actions = new Actions(getDriver());
334 WebElement area = getWebElementByClassName(className);
335 actions.moveToElement(area).perform();
336 GeneralUIUtils.ultimateWait();
340 public static void waitForLoader() {
341 waitForLoader(TIME_OUT);
344 public static void waitForLoader(int timeOut) {
345 final String loaderClass = "tlv-loader";
346 final int sleepDuration = 500;
347 sleep(sleepDuration);
348 LOGGER.debug("Waiting {}s for '.{}'", timeOut, loaderClass);
349 waitForElementInVisibilityBy(By.className(loaderClass), timeOut);
352 public static void findComponentAndClick(final String resourceName) {
353 HomePage.findComponentAndClick(resourceName);
356 public static void windowZoomOut() {
357 final int zoomOutFactor = 3;
358 for (int i = 0; i < zoomOutFactor; i++) {
359 if (getDriver() instanceof FirefoxDriver) {
360 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
365 public static void resetZoom() {
366 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
369 public static void windowZoomOutUltimate() {
374 public static void sleep(int duration) {
376 Thread.sleep(duration);
377 } catch (final InterruptedException e) {
378 Thread.currentThread().interrupt();
379 throw new GeneralUiRuntimeException("The thread was interrupted during a sleep", e);
383 public static void moveToStep(final DataTestIdEnum.StepsEnum stepName) {
384 getExtendTest().log(Status.INFO, String.format("Going to %s page ", stepName.toString()));
385 moveToStep(stepName.getValue());
388 public static void moveToStep(final String dataTestId) {
389 clickOnElementByTestId(dataTestId);
393 public static Select getSelectList(String item, String datatestsid) {
394 Select selectList = new Select(getWebElementByTestID(datatestsid));
396 selectList.selectByVisibleText(item);
401 public static List<WebElement> getElementsByCSS(String cssString) /*throws InterruptedException*/ {
402 GeneralUIUtils.waitForLoader();
403 return getDriver().findElements(By.cssSelector(cssString));
406 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString) {
407 GeneralUIUtils.waitForLoader();
408 return parentElement.findElement(By.cssSelector(cssString));
411 private static WebElement highlightMyElement(WebElement element) {
412 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
413 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
417 public static WebElement getSelectedElementFromDropDown(String dataTestId) {
418 GeneralUIUtils.ultimateWait();
419 return new Select(getDriver().findElement(By.xpath(String.format(DATA_TESTS_ID, dataTestId, "']")))).getFirstSelectedOption();
422 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
423 int maxWaitingPeriodMS = MAX_WAITING_PERIOD;
424 int napPeriodMS = NAP_PERIOD;
425 int sumOfWaiting = 0;
426 List<WebElement> elements;
427 boolean isKeepWaiting = false;
428 while (!isKeepWaiting) {
429 elements = func.get();
430 isKeepWaiting = (expectedElementsCount == elements.size());
432 sumOfWaiting += napPeriodMS;
433 if (sumOfWaiting > maxWaitingPeriodMS) {
440 public static String getActionDuration(Runnable func) {
441 long startTime = System.nanoTime();
443 long estimateTime = System.nanoTime();
444 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
445 return String.format("%02`d:%02d", duration / DURATION_FORMATIN, duration % DURATION_FORMATIN);
448 public static WebElement clickOnAreaJS(String areaId) {
449 return clickOnAreaJS(areaId, TIME_OUT);
453 public static WebElement clickOnAreaJS(String areaId, int timeout) {
456 WebElement area = getWebElementByTestID(areaId);
457 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
458 Object executeScript = javascript.executeScript("arguments[0].click();", area, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
459 waitForLoader(timeout);
462 } catch (Exception e) {
469 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
470 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
471 javascript.executeScript("arguments[0].click();", areaId, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
476 public static void clickSomewhereOnPage() {
477 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
480 public static void clickOnElementByText(String textInElement) {
481 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
482 highlightMyElement(wait.until(
483 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
486 public static void clickOnElementByText(String textInElement, int customTimeout) {
487 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
488 highlightMyElement(wait.until(
489 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
492 public static void clickJSOnElementByText(String textInElement) throws Exception {
493 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
494 clickOnAreaJS(wait.until(
495 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
498 public static void waitForAngular() {
499 LOGGER.debug("Waiting for angular");
500 final int webDriverWaitingTime = 90;
501 WebDriverWait wait = new WebDriverWait(getDriver(), webDriverWaitingTime, NAP_PERIOD);
502 wait.until(AdditionalConditions.pageLoadWait());
503 wait.until(AdditionalConditions.angularHasFinishedProcessing());
504 LOGGER.debug("Waiting for angular finished");
507 public static Object getAllElementAttributes(WebElement element) {
508 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);
511 public static boolean isElementReadOnly(WebElement element) {
513 highlightMyElement(element).clear();
515 } catch (Exception e) {
520 public static boolean isElementReadOnly(String dataTestId) {
521 return isElementReadOnly(
522 waitForElementVisibilityByTestId(dataTestId));
525 public static boolean isElementDisabled(WebElement element) {
526 return highlightMyElement(element).getAttribute("class").contains("view-mode")
527 || element.getAttribute("class").contains("disabled") || element.getAttribute("disabled") != null;
530 public static boolean isElementDisabled(String dataTestId) {
531 return isElementDisabled(
532 waitForElementVisibilityByTestId(dataTestId));
535 public static void ultimateWait() {
536 long startTime = System.nanoTime();
538 GeneralUIUtils.waitForLoader();
539 GeneralUIUtils.waitForBackLoader();
540 GeneralUIUtils.waitForAngular();
542 long estimateTime = System.nanoTime();
543 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
544 if (duration > TIME_OUT) {
545 getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
549 public static WebElement unhideElement(WebElement element, String attributeValue) {
550 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
551 ((JavascriptExecutor) getDriver()).executeScript(js, element);
555 public static WebElement findByText(String textInElement) {
556 return getDriver().findElement(searchByTextContaining(textInElement));
559 public static By searchByTextContaining(String textInElement) {
560 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
563 public static WebElement getClickableButtonBy(By by, int timout) {
565 WebDriverWait wait = new WebDriverWait(getDriver(), timout);
566 return wait.until(ExpectedConditions.elementToBeClickable(by));
567 } catch (Exception e) {
573 public static WebElement getButtonWithText(String textInButton) {
575 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
576 } catch (Exception e) {
581 public static void closeErrorMessage() {
582 WebElement okWebElement = getButtonWithText("OK");
583 if (okWebElement != null) {
584 okWebElement.click();
589 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
591 return getDriver().findElement(By.cssSelector(cssString));
594 public static String getDataTestIdAttributeValue(WebElement element) {
595 return element.getAttribute("data-tests-id");
598 public static String getTextContentAttributeValue(WebElement element) {
599 return element.getAttribute("textContent");
602 public static void clickOnElementByCSS(String cssString) throws Exception {
603 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
604 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
608 public static boolean checkForDisabledAttribute(String dataTestId) {
609 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
610 return elementAttributes.toString().contains("disabled");
613 public static void dragAndDropElementByY(WebElement area, int yOffset) {
614 final int dragAndDropTimeout = 10;
615 Actions actions = new Actions(getDriver());
616 actions.dragAndDropBy(area, dragAndDropTimeout, yOffset).perform();
620 public static void waitForBackLoader() {
621 waitForBackLoader(TIME_OUT);
624 public static void waitForBackLoader(int timeOut) {
626 final String backLoaderClass = "tlv-loader-back";
627 LOGGER.debug("Waiting {}s for '.{}'", timeOut, backLoaderClass);
628 waitForElementInVisibilityBy(By.className(backLoaderClass), timeOut);
631 public static void addStringtoClipboard(String text) {
632 StringSelection selection = new StringSelection(text);
633 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
634 clipboard.setContents(selection, selection);
637 public static boolean checkForDisabledAttributeInHiddenElement(String cssString) {
638 final int numberOfDisableElements = 3;
639 boolean isDisabled = false;
640 for (int i = 0; i < numberOfDisableElements; i++) {
641 Object elementAttributes = getAllElementAttributes(getWebElementByPresence(By.cssSelector(cssString), TIME_OUT));
642 isDisabled = elementAttributes.toString().contains("disabled");
651 public static void selectByValueTextContained(String dataTestsId, String value) {
653 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)));
655 boolean matched = false;
656 for (WebElement option : options) {
662 throw new NoSuchElementException("Cannot locate option with value: " + value);
668 public static void setTextInElementByXpath(String xPath, String text) {
669 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
672 webElement.sendKeys(text);
677 public static void clickOnElementByXpath(String xPath) {
678 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
683 public static String getTextValueFromWebElementByXpath(String xpath) {
684 WebElement webElement = getWebElementBy(By.xpath(xpath));
685 return webElement.getAttribute("value");
688 public static List<WebElement> findElementsByXpath(String xPath) {
689 return getDriver().findElements(By.xpath(xPath));
692 public static void clickOnBrowserBackButton() throws Exception {
693 getExtendTest().log(Status.INFO, "Going to press on back browser button.");
694 getDriver().navigate().back();
698 public static String copyCurrentURL() throws Exception {
699 getExtendTest().log(Status.INFO, "Copying current URL");
700 return getDriver().getCurrentUrl();
703 public static void navigateToURL(String url) throws Exception {
704 getExtendTest().log(Status.INFO, "Navigating to URL " + url);
705 getDriver().navigate().to(url);
708 public static void refreshWebpage() throws Exception {
709 getExtendTest().log(Status.INFO, "Refreshing Webpage");
710 getDriver().navigate().refresh();
714 public static Object getElementPositionOnCanvas(String elementName) {
715 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
716 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
717 + "var nPos = n.renderedPosition();\n"
718 + "return JSON.stringify({\n"
722 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
725 public static Object getElementGreenDotPositionOnCanvas(String elementName) {
726 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
727 + "var cyZoom = cy.zoom();\n"
728 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
729 + "var nPos = n.renderedPosition();\n"
730 + "var nData = n.data();\n"
731 + "var nImgSize = nData.imgWidth;\n"
732 + "var shiftSize = (nImgSize-18)*cyZoom/2;\n"
733 + "return JSON.stringify({\n"
734 + "\tx: nPos.x + shiftSize,\n"
735 + "\ty: nPos.y - shiftSize\n"
737 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
740 public static Long getAndValidateActionDuration(Runnable action, int regularTestRunTime) {
741 Long actualTestRunTime = null;
743 actualTestRunTime = Utils.getActionDuration(() -> {
746 } catch (Throwable throwable) {
747 throwable.printStackTrace();
750 } catch (Exception e) {
753 final double factor = 1.5;
755 assertTrue("Expected test run time should be less than " + regularTestRunTime * factor + ", "
756 + "actual time is " + actualTestRunTime, regularTestRunTime * factor > actualTestRunTime);
757 //SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is " + actualTestRunTime + " seconds");
758 return actualTestRunTime;