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.pages.HomePage;
29 import org.openecomp.sdc.ci.tests.utils.Utils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.JavascriptExecutor;
32 import org.openqa.selenium.Keys;
33 import org.openqa.selenium.NoSuchElementException;
34 import org.openqa.selenium.OutputType;
35 import org.openqa.selenium.TakesScreenshot;
36 import org.openqa.selenium.WebDriver;
37 import org.openqa.selenium.WebElement;
38 import org.openqa.selenium.firefox.FirefoxDriver;
39 import org.openqa.selenium.interactions.Actions;
40 import org.openqa.selenium.support.ui.ExpectedConditions;
41 import org.openqa.selenium.support.ui.Select;
42 import org.openqa.selenium.support.ui.WebDriverWait;
44 import java.awt.Toolkit;
45 import java.awt.datatransfer.Clipboard;
46 import java.awt.datatransfer.StringSelection;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.List;
51 import java.util.UUID;
52 import java.util.concurrent.TimeUnit;
53 import java.util.function.Supplier;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 import static org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest.getExtendTest;
58 import static org.testng.AssertJUnit.assertTrue;
61 public final class GeneralUIUtils {
63 private static final Logger LOGGER = LoggerFactory.getLogger(GeneralUIUtils.class);
65 private static final String DATA_TESTS_ID = "//*[@data-tests-id='%1$s' or @data-test-id='%1$s']";
66 private static final String COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW = "color: yellow; border: 4px solid yellow;";
68 private static final int TIME_OUT = (int) (60 * 1.5);
69 private static final int WEB_DRIVER_WAIT_TIME_OUT = 10;
70 private static final int SLEEP_DURATION = 1000;
71 private static final int MAX_WAITING_PERIOD = 10 * 1000;
72 private static final int NAP_PERIOD = 100;
73 private static final int DURATION_FORMATIN = 60;
75 private GeneralUIUtils () {
79 public static int getTimeOut() {
83 public static WebDriver getDriver() {
84 return DriverFactory.getDriver();
87 public static List<WebElement> getElementsByLocator(By by) {
88 return getDriver().findElements(by);
91 public static File takeScreenshot(String screenshotFilename, String dir, String testName) throws IOException {
92 if (screenshotFilename == null) {
93 if (testName != null) {
94 screenshotFilename = testName;
96 screenshotFilename = UUID.randomUUID().toString();
100 File scrFile = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);
101 File filePath = new File(String.format("%s/%s.png", dir, screenshotFilename));
102 new File(dir).mkdirs();
103 FileUtils.copyFile(scrFile, filePath);
105 } catch (IOException e1) {
106 e1.printStackTrace();
111 public static File takeScreenshot(String screenshotFilename, String dir) throws IOException {
112 return takeScreenshot(screenshotFilename, dir, null);
115 public static WebElement getWebElementByTestID(String dataTestId) {
116 return getWebElementByTestID(dataTestId, TIME_OUT);
119 public static WebElement getWebElementByTestID(final String dataTestId, final int timeout) {
120 final WebDriverWait wait = new WebDriverWait(getDriver(), timeout);
122 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId))));
125 public static boolean isWebElementExistByTestId(String dataTestId) {
126 return getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId))).size() != 0;
129 public static boolean isWebElementExistByClass(String className) {
130 return getDriver().findElements(By.className(className)).size() != 0;
133 public static WebElement getInputElement(String dataTestId) {
136 return getDriver().findElement(By.xpath(String.format(DATA_TESTS_ID, dataTestId)));
137 } catch (Exception e) {
142 public static List<WebElement> getInputElements(String dataTestId) {
144 return getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId)));
148 public static WebElement getWebElementBy(By by) {
149 return getWebElementBy(by, TIME_OUT);
152 public static WebElement getWebElementBy(By by, int timeOut) {
153 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
154 return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
157 public static WebElement getWebElementByPresence(By by, int timeOut) {
158 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
159 return wait.until(ExpectedConditions.presenceOfElementLocated(by));
162 public static List<String> getWebElementListText(List<WebElement> elements) {
163 List<String> Text = new ArrayList<>();
164 for (WebElement webElement : elements) {
165 Text.add(webElement.getText());
170 public static List<WebElement> getWebElementsListBy(By by) {
171 return getWebElementsListBy(by, TIME_OUT);
174 public static List<WebElement> getWebElementsListBy(By by, int timeOut) {
175 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
176 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(by));
179 public static List<WebElement> getWebElementsListByContainTestID(String dataTestId) {
181 WebDriverWait wait = new WebDriverWait(getDriver(), WEB_DRIVER_WAIT_TIME_OUT);
182 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(String.format("//*[contains(@data-tests-id, '%1$s') or contains(@data-test-id, '%1$s')]", dataTestId))));
183 } catch (Exception e) {
184 return new ArrayList<WebElement>();
188 public static List<WebElement> getWebElementsListByContainsClassName(String containedText) {
189 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
190 return wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[contains(@class, '" + containedText + "')]")));
193 public static WebElement getWebElementByContainsClassName(String containedText) {
194 return getWebElementBy(By.xpath("//*[contains(@class, '" + containedText + "')]"));
197 public static WebElement getWebElementByClassName(String className) {
198 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
199 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.className(className)));
202 public static List<WebElement> getWebElementsListByTestID(String dataTestId) {
203 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
204 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(String.format(DATA_TESTS_ID, dataTestId))));
207 public static List<WebElement> getWebElementsListByClassName(String className) {
208 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
209 return wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
213 public static Boolean isElementInvisibleByTestId(String dataTestId) {
214 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
216 ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId))));
219 public static Boolean isElementVisibleByTestId(String dataTestId) {
221 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
222 return wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath(String.format(DATA_TESTS_ID, dataTestId))))).isDisplayed();
223 } catch (Exception e) {
228 public static void clickOnElementByTestId(String dataTestId) {
229 LOGGER.debug("Clicking on the element by test id " + dataTestId);
230 clickOnElementByTestIdWithoutWait(dataTestId);
231 LOGGER.debug("Waiting after clicking element by test id " + dataTestId);
233 LOGGER.debug(String.format("Waiting after clicking element by test id '%s' finished", dataTestId));
236 public static void clickOnElementChildByTestId(String dataTestId) {
237 clickOnElementChildByTestIdWithoutWait(dataTestId);
241 public static void clickOnElementByTestIdWithoutWait(final String dataTestId) {
242 final WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
244 .until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(DATA_TESTS_ID, dataTestId)))).click();
247 public static void clickOnElementChildByTestIdWithoutWait(String dataTestId) {
248 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
249 wait.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(DATA_TESTS_ID, dataTestId) + "//*"))).click();
252 public static void clickOnElementByTestId(String dataTestId, int customTimeout) {
253 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
254 wait.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(DATA_TESTS_ID, dataTestId)))).click();
257 public static WebElement waitForElementVisibilityByTestId(String dataTestId) {
258 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
259 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId))));
262 public static Boolean waitForElementInVisibilityByTestId(String dataTestId) {
263 return waitForElementInVisibilityByTestId(dataTestId, TIME_OUT);
266 public static Boolean waitForElementInVisibilityByTestId(String dataTestId, int timeOut) {
267 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
268 boolean displayed = getDriver().findElements(By.xpath(String.format(DATA_TESTS_ID, dataTestId))).isEmpty();
270 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(String.format(DATA_TESTS_ID, dataTestId))));
277 public static Boolean waitForElementInVisibilityByTestId(By by) {
278 return waitForElementInVisibilityBy(by, TIME_OUT);
282 public static Boolean waitForElementInVisibilityBy(By by, int timeOut) {
283 WebDriverWait wait = new WebDriverWait(getDriver(), timeOut);
284 boolean displayed = getDriver().findElements(by).isEmpty();
286 Boolean until = wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
287 sleep(SLEEP_DURATION);
294 public static void setWebElementByTestId(String elemetID, String value) {
295 WebElement resourceDescriptionTextbox = GeneralUIUtils.getWebElementByTestID(elemetID);
296 resourceDescriptionTextbox.clear();
297 resourceDescriptionTextbox.sendKeys(value);
301 public static WebElement hoverOnAreaByTestId(String areaId) {
302 Actions actions = new Actions(getDriver());
303 WebElement area = getWebElementByTestID(areaId);
304 actions.moveToElement(area).perform();
309 public static WebElement hoverOnAreaByClassName(String className) {
310 Actions actions = new Actions(getDriver());
311 WebElement area = getWebElementByClassName(className);
312 actions.moveToElement(area).perform();
313 GeneralUIUtils.ultimateWait();
317 public static void waitForLoader() {
318 waitForLoader(TIME_OUT);
321 public static void waitForLoader(int timeOut) {
322 final String loaderClass = "tlv-loader";
323 final int sleepDuration = 500;
324 sleep(sleepDuration);
325 LOGGER.debug("Waiting {}s for '.{}'", timeOut, loaderClass);
326 waitForElementInVisibilityBy(By.className(loaderClass), timeOut);
329 public static void findComponentAndClick(final String resourceName) {
330 HomePage.findComponentAndClick(resourceName);
333 public static void windowZoomOut() {
334 final int zoomOutFactor = 3;
335 for (int i = 0; i < zoomOutFactor; i++) {
336 if (getDriver() instanceof FirefoxDriver) {
337 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
342 public static void resetZoom() {
343 getDriver().findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
346 public static void windowZoomOutUltimate() {
351 public static void sleep(int duration) {
353 Thread.sleep(duration);
354 } catch (final InterruptedException e) {
355 Thread.currentThread().interrupt();
356 throw new GeneralUiRuntimeException("The thread was interrupted during a sleep", e);
360 public static void moveToStep(final DataTestIdEnum.StepsEnum stepName) {
361 getExtendTest().log(Status.INFO, String.format("Going to %s page ", stepName.toString()));
362 moveToStep(stepName.getValue());
365 public static void moveToStep(final String dataTestId) {
366 clickOnElementChildByTestId(dataTestId);
370 public static Select getSelectList(String item, String datatestsid) {
371 Select selectList = new Select(getWebElementByTestID(datatestsid));
373 selectList.selectByVisibleText(item);
378 public static List<WebElement> getElementsByCSS(String cssString) /*throws InterruptedException*/ {
379 GeneralUIUtils.waitForLoader();
380 return getDriver().findElements(By.cssSelector(cssString));
383 public static WebElement getElementfromElementByCSS(WebElement parentElement, String cssString) {
384 GeneralUIUtils.waitForLoader();
385 return parentElement.findElement(By.cssSelector(cssString));
388 private static WebElement highlightMyElement(WebElement element) {
389 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
390 javascript.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
394 public static WebElement getSelectedElementFromDropDown(String dataTestId) {
395 GeneralUIUtils.ultimateWait();
396 return new Select(getDriver().findElement(By.xpath(String.format(DATA_TESTS_ID, dataTestId)))).getFirstSelectedOption();
399 public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
400 int maxWaitingPeriodMS = MAX_WAITING_PERIOD;
401 int napPeriodMS = NAP_PERIOD;
402 int sumOfWaiting = 0;
403 List<WebElement> elements;
404 boolean isKeepWaiting = false;
405 while (!isKeepWaiting) {
406 elements = func.get();
407 isKeepWaiting = (expectedElementsCount == elements.size());
409 sumOfWaiting += napPeriodMS;
410 if (sumOfWaiting > maxWaitingPeriodMS) {
417 public static String getActionDuration(Runnable func) throws Exception {
418 long startTime = System.nanoTime();
420 long estimateTime = System.nanoTime();
421 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
422 return String.format("%02d:%02d", duration / DURATION_FORMATIN, duration % DURATION_FORMATIN);
425 public static WebElement clickOnAreaJS(String areaId) {
426 return clickOnAreaJS(areaId, TIME_OUT);
430 public static WebElement clickOnAreaJS(String areaId, int timeout) {
433 WebElement area = getWebElementByTestID(areaId);
434 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
435 Object executeScript = javascript.executeScript("arguments[0].click();", area, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
436 waitForLoader(timeout);
439 } catch (Exception e) {
446 public static WebElement clickOnAreaJS(WebElement areaId) throws InterruptedException {
447 JavascriptExecutor javascript = (JavascriptExecutor) getDriver();
448 javascript.executeScript("arguments[0].click();", areaId, COLOR_YELLOW_BORDER_4PX_SOLID_YELLOW);
453 public static void clickSomewhereOnPage() {
454 getDriver().findElement(By.cssSelector(".asdc-app-title")).click();
457 public static void clickOnElementByText(String textInElement) {
458 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
459 highlightMyElement(wait.until(
460 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
463 public static void clickOnElementByText(String textInElement, int customTimeout) {
464 WebDriverWait wait = new WebDriverWait(getDriver(), customTimeout);
465 highlightMyElement(wait.until(
466 ExpectedConditions.elementToBeClickable(findByText(textInElement)))).click();
469 public static void clickJSOnElementByText(String textInElement) throws Exception {
470 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
471 clickOnAreaJS(wait.until(
472 ExpectedConditions.elementToBeClickable(findByText(textInElement))));
475 public static void waitForAngular() {
476 LOGGER.debug("Waiting for angular");
477 final int webDriverWaitingTime = 90;
478 WebDriverWait wait = new WebDriverWait(getDriver(), webDriverWaitingTime, NAP_PERIOD);
479 wait.until(AdditionalConditions.pageLoadWait());
480 wait.until(AdditionalConditions.angularHasFinishedProcessing());
481 LOGGER.debug("Waiting for angular finished");
484 public static Object getAllElementAttributes(WebElement element) {
485 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);
488 public static boolean isElementReadOnly(WebElement element) {
490 highlightMyElement(element).clear();
492 } catch (Exception e) {
497 public static boolean isElementReadOnly(String dataTestId) {
498 return isElementReadOnly(
499 waitForElementVisibilityByTestId(dataTestId));
502 public static boolean isElementDisabled(WebElement element) {
503 return highlightMyElement(element).getAttribute("class").contains("view-mode")
504 || element.getAttribute("class").contains("disabled") || element.getAttribute("disabled") != null;
507 public static boolean isElementDisabled(String dataTestId) {
508 return isElementDisabled(
509 waitForElementVisibilityByTestId(dataTestId));
512 public static void ultimateWait() {
513 long startTime = System.nanoTime();
515 GeneralUIUtils.waitForLoader();
516 GeneralUIUtils.waitForBackLoader();
517 GeneralUIUtils.waitForAngular();
519 long estimateTime = System.nanoTime();
520 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
521 if (duration > TIME_OUT) {
522 getExtendTest().log(Status.WARNING, String.format("Delays on page, %d seconds", duration));
526 public static WebElement unhideElement(WebElement element, String attributeValue) {
527 String js = "arguments[0].setAttribute('class','" + attributeValue + "');";
528 ((JavascriptExecutor) getDriver()).executeScript(js, element);
532 public static WebElement findByText(String textInElement) {
533 return getDriver().findElement(searchByTextContaining(textInElement));
536 public static By searchByTextContaining(String textInElement) {
537 return By.xpath("//*[contains(text(),'" + textInElement + "')]");
540 public static WebElement getClickableButtonBy(By by, int timout) {
542 WebDriverWait wait = new WebDriverWait(getDriver(), timout);
543 return wait.until(ExpectedConditions.elementToBeClickable(by));
544 } catch (Exception e) {
550 public static WebElement getButtonWithText(String textInButton) {
552 return getDriver().findElement(By.xpath("//button[contains(text(),'" + textInButton + "')]"));
553 } catch (Exception e) {
558 public static void closeErrorMessage() {
559 WebElement okWebElement = getButtonWithText("OK");
560 if (okWebElement != null) {
561 okWebElement.click();
566 public static WebElement getElementByCSS(String cssString) throws InterruptedException {
568 return getDriver().findElement(By.cssSelector(cssString));
571 public static String getDataTestIdAttributeValue(WebElement element) {
572 return element.getAttribute("data-tests-id");
575 public static String getTextContentAttributeValue(WebElement element) {
576 return element.getAttribute("textContent");
579 public static void clickOnElementByCSS(String cssString) throws Exception {
580 WebDriverWait wait = new WebDriverWait(getDriver(), TIME_OUT);
581 wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(cssString))).click();
585 public static boolean checkForDisabledAttribute(String dataTestId) {
586 Object elementAttributes = getAllElementAttributes(waitForElementVisibilityByTestId(dataTestId));
587 return elementAttributes.toString().contains("disabled");
590 public static void dragAndDropElementByY(WebElement area, int yOffset) {
591 final int dragAndDropTimeout = 10;
592 Actions actions = new Actions(getDriver());
593 actions.dragAndDropBy(area, dragAndDropTimeout, yOffset).perform();
597 public static void waitForBackLoader() {
598 waitForBackLoader(TIME_OUT);
601 public static void waitForBackLoader(int timeOut) {
603 final String backLoaderClass = "tlv-loader-back";
604 LOGGER.debug("Waiting {}s for '.{}'", timeOut, backLoaderClass);
605 waitForElementInVisibilityBy(By.className(backLoaderClass), timeOut);
608 public static void addStringtoClipboard(String text) {
609 StringSelection selection = new StringSelection(text);
610 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
611 clipboard.setContents(selection, selection);
614 public static boolean checkForDisabledAttributeInHiddenElement(String cssString) {
615 final int numberOfDisableElements = 3;
616 boolean isDisabled = false;
617 for (int i = 0; i < numberOfDisableElements; i++) {
618 Object elementAttributes = getAllElementAttributes(getWebElementByPresence(By.cssSelector(cssString), TIME_OUT));
619 isDisabled = elementAttributes.toString().contains("disabled");
628 public static void selectByValueTextContained(String dataTestsId, String value) {
630 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)));
632 boolean matched = false;
633 for (WebElement option : options) {
639 throw new NoSuchElementException("Cannot locate option with value: " + value);
645 public static void setTextInElementByXpath(String xPath, String text) {
646 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
649 webElement.sendKeys(text);
654 public static void clickOnElementByXpath(String xPath) {
655 WebElement webElement = GeneralUIUtils.getWebElementBy(By.xpath(xPath));
660 public static String getTextValueFromWebElementByXpath(String xpath) {
661 WebElement webElement = getWebElementBy(By.xpath(xpath));
662 return webElement.getAttribute("value");
665 public static List<WebElement> findElementsByXpath(String xPath) {
666 return getDriver().findElements(By.xpath(xPath));
669 public static void clickOnBrowserBackButton() throws Exception {
670 getExtendTest().log(Status.INFO, "Going to press on back browser button.");
671 getDriver().navigate().back();
675 public static String copyCurrentURL() throws Exception {
676 getExtendTest().log(Status.INFO, "Copying current URL");
677 return getDriver().getCurrentUrl();
680 public static void navigateToURL(String url) throws Exception {
681 getExtendTest().log(Status.INFO, "Navigating to URL " + url);
682 getDriver().navigate().to(url);
685 public static void refreshWebpage() throws Exception {
686 getExtendTest().log(Status.INFO, "Refreshing Webpage");
687 getDriver().navigate().refresh();
691 public static Object getElementPositionOnCanvas(String elementName) {
692 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
693 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
694 + "var nPos = n.renderedPosition();\n"
695 + "return JSON.stringify({\n"
699 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
702 public static Object getElementGreenDotPositionOnCanvas(String elementName) {
703 String scriptJS = "var cy = window.jQuery('.sdc-composition-graph-wrapper').cytoscape('get');\n"
704 + "var cyZoom = cy.zoom();\n"
705 + "var n = cy.nodes('[name=\"" + elementName + "\"]');\n"
706 + "var nPos = n.renderedPosition();\n"
707 + "var nData = n.data();\n"
708 + "var nImgSize = nData.imgWidth;\n"
709 + "var shiftSize = (nImgSize-18)*cyZoom/2;\n"
710 + "return JSON.stringify({\n"
711 + "\tx: nPos.x + shiftSize,\n"
712 + "\ty: nPos.y - shiftSize\n"
714 return ((JavascriptExecutor) getDriver()).executeScript(scriptJS);
717 public static Long getAndValidateActionDuration(Runnable action, int regularTestRunTime) {
718 Long actualTestRunTime = null;
720 actualTestRunTime = Utils.getActionDuration(() -> {
723 } catch (Throwable throwable) {
724 throwable.printStackTrace();
727 } catch (Exception e) {
730 final double factor = 1.5;
732 assertTrue("Expected test run time should be less than " + regularTestRunTime * factor + ", "
733 + "actual time is " + actualTestRunTime, regularTestRunTime * factor > actualTestRunTime);
734 //SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is " + actualTestRunTime + " seconds");
735 return actualTestRunTime;