Class TestBenchHelpers

  • All Implemented Interfaces:
    com.vaadin.testbench.HasDriver, com.vaadin.testbench.HasElementQuery, com.vaadin.testbench.HasSearchContext, com.vaadin.testbench.HasTestBenchCommandExecutor
    Direct Known Subclasses:
    AbstractParallelTestBenchTest, AbstractTestBenchTest

    public class TestBenchHelpers
    extends com.vaadin.testbench.parallel.ParallelTest
    Helpers for running testbench tests.
    Since:
    1.0
    • Field Summary

      • Fields inherited from class com.vaadin.testbench.parallel.ParallelTest

        screenshotOnFailure
      • Fields inherited from class com.vaadin.testbench.TestBenchTestCase

        driver, maxAttempts, testbenchVersion
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void assertEquals​(org.openqa.selenium.WebElement expectedElement, org.openqa.selenium.WebElement actualElement)
      Assert that the two elements are equal.
      void blur()
      Calls the blur() function on the current active element of the page, if any.
      protected void checkLogsForErrors()
      Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.
      protected void checkLogsForErrors​(Predicate<String> acceptableMessagePredicate)
      Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.
      protected void clickElementWithJs​(String elementId)
      Clicks on the element, using JS.
      protected void clickElementWithJs​(org.openqa.selenium.WebElement element)
      Clicks on the element, using JS.
      void drag​(org.openqa.selenium.WebElement source)
      Simulate only a drag of source.
      void dragAndDrop​(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target)
      Simulate DnD of source element into the target element.
      void dragElementOver​(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target)
      Simulate a drag of source element and over the target element.
      protected Object executeScript​(String script, Object... args)
      Executes the given JavaScript.
      protected List<org.openqa.selenium.logging.LogEntry> getLogEntries​(Level level)
      Gets the log entries from the browser that have the given logging level or higher.
      protected int getScrollX()
      Gets current scroll position on x axis.
      protected int getScrollY()
      Gets current scroll position on y axis.
      protected boolean hasCssClass​(org.openqa.selenium.WebElement element, String className)
      Checks if the given element has the given class name.
      boolean isElementPresent​(org.openqa.selenium.By by)
      Returns true if an element can be found from the driver with given selector.
      protected void scrollBy​(int deltaX, int deltaY)
      Scrolls the page by given amount of x and y deltas.
      protected void scrollIntoViewAndClick​(org.openqa.selenium.WebElement element)
      Scrolls the page to the element specified and clicks it.
      protected void scrollToElement​(org.openqa.selenium.WebElement element)
      Scrolls the page to the element given using javascript.
      protected void waitForDevServer()
      If dev server start in progress wait until it's started.
      protected void waitForElementNotPresent​(org.openqa.selenium.By by)  
      protected void waitForElementPresent​(org.openqa.selenium.By by)  
      protected void waitForElementVisible​(org.openqa.selenium.By by)  
      protected <T> void waitUntilNot​(org.openqa.selenium.support.ui.ExpectedCondition<T> condition)
      Waits up to 10s for the given condition to become false.
      protected <T> void waitUntilNot​(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds)
      Waits the given number of seconds for the given condition to become false.
      • Methods inherited from class com.vaadin.testbench.parallel.ParallelTest

        getDefaultCapabilities, getDesiredCapabilities, getHubHostname, getHubURL, getRunLocallyBrowser, getRunLocallyBrowserVersion, getRunOnHub, setDesiredCapabilities, setup
      • Methods inherited from class com.vaadin.testbench.TestBenchTestCase

        concatUrl, findElement, findElements, getCommandExecutor, getContext, getDriver, setDriver, testBench, waitUntil, waitUntil, wrap
      • Methods inherited from interface com.vaadin.testbench.HasElementQuery

        $, $
    • Constructor Detail

      • TestBenchHelpers

        public TestBenchHelpers()
    • Method Detail

      • waitUntilNot

        protected <T> void waitUntilNot​(org.openqa.selenium.support.ui.ExpectedCondition<T> condition)
        Waits up to 10s for the given condition to become false. Use e.g. as waitUntilNot(ExpectedCondition).
        Type Parameters:
        T - the return type of the expected condition
        Parameters:
        condition - the condition to wait for to become false
      • isElementPresent

        public boolean isElementPresent​(org.openqa.selenium.By by)
        Returns true if an element can be found from the driver with given selector.
        Parameters:
        by - the selector used to find element
        Returns:
        true if the element can be found
      • dragAndDrop

        public void dragAndDrop​(org.openqa.selenium.WebElement source,
                                org.openqa.selenium.WebElement target)
        Simulate DnD of source element into the target element.
        Parameters:
        source -
        target -
      • drag

        public void drag​(org.openqa.selenium.WebElement source)
        Simulate only a drag of source.
        Parameters:
        source -
      • dragElementOver

        public void dragElementOver​(org.openqa.selenium.WebElement source,
                                    org.openqa.selenium.WebElement target)
        Simulate a drag of source element and over the target element.
        Parameters:
        source -
        target -
      • waitUntilNot

        protected <T> void waitUntilNot​(org.openqa.selenium.support.ui.ExpectedCondition<T> condition,
                                        long timeoutInSeconds)
        Waits the given number of seconds for the given condition to become false. Use e.g. as waitUntilNot(ExpectedCondition).
        Type Parameters:
        T - the return type of the expected condition
        Parameters:
        condition - the condition to wait for to become false
        timeoutInSeconds - the number of seconds to wait
      • waitForElementPresent

        protected void waitForElementPresent​(org.openqa.selenium.By by)
      • waitForElementNotPresent

        protected void waitForElementNotPresent​(org.openqa.selenium.By by)
      • waitForElementVisible

        protected void waitForElementVisible​(org.openqa.selenium.By by)
      • hasCssClass

        protected boolean hasCssClass​(org.openqa.selenium.WebElement element,
                                      String className)
        Checks if the given element has the given class name. Matches only full class names, i.e. has ("foo") does not match class="foobar"
        Parameters:
        element - the element to test
        className - the class names to match
        Returns:
        true if matches, false if not
      • assertEquals

        protected static void assertEquals​(org.openqa.selenium.WebElement expectedElement,
                                           org.openqa.selenium.WebElement actualElement)
        Assert that the two elements are equal.

        Can be removed if https://dev.vaadin.com/ticket/18484 is fixed.

        Parameters:
        expectedElement - the expected element
        actualElement - the actual element
      • executeScript

        protected Object executeScript​(String script,
                                       Object... args)
        Executes the given JavaScript.

        To send arguments to the script, you can use the arguments variable.
        For example: executeScript("window.alert(arguments[0]);", "Alert message!");.

        To be able to use the return value of the JavaScript, you must explicitly declare a return statement.
        For example: executeScript("return window.name;");.

        Overrides:
        executeScript in class com.vaadin.testbench.TestBenchTestCase
        Parameters:
        script - the script to execute
        args - optional arguments for the script
        Returns:
        whatever JavascriptExecutor.executeScript(String, Object...) returns
      • scrollBy

        protected void scrollBy​(int deltaX,
                                int deltaY)
        Scrolls the page by given amount of x and y deltas. Actual scroll values can be different if any delta is bigger then the corresponding document dimension.
        Parameters:
        deltaX - the offset in pixels to scroll horizontally
        deltaY - the offset in pixels to scroll vertically
      • scrollToElement

        protected void scrollToElement​(org.openqa.selenium.WebElement element)
        Scrolls the page to the element given using javascript. Standard Selenium api does not work for current newest Chrome and ChromeDriver.
        Parameters:
        element - the element to scroll to, not null
      • scrollIntoViewAndClick

        protected void scrollIntoViewAndClick​(org.openqa.selenium.WebElement element)
        Scrolls the page to the element specified and clicks it.
        Parameters:
        element - the element to scroll to and click
      • getScrollX

        protected int getScrollX()
        Gets current scroll position on x axis.
        Returns:
        current scroll position on x axis.
      • getScrollY

        protected int getScrollY()
        Gets current scroll position on y axis.
        Returns:
        current scroll position on y axis.
      • clickElementWithJs

        protected void clickElementWithJs​(String elementId)
        Clicks on the element, using JS. This method is more convenient then Selenium findElement(By.id(urlId)).click(), because Selenium method changes scroll position, which is not always needed.
        Parameters:
        elementId - id of the
      • clickElementWithJs

        protected void clickElementWithJs​(org.openqa.selenium.WebElement element)
        Clicks on the element, using JS. This method is more convenient then Selenium element.click(), because Selenium method changes scroll position, which is not always needed.
        Parameters:
        element - the element to be clicked on
      • getLogEntries

        protected List<org.openqa.selenium.logging.LogEntry> getLogEntries​(Level level)
        Gets the log entries from the browser that have the given logging level or higher.
        Parameters:
        level - the minimum severity of logs included
        Returns:
        log entries from the browser
      • checkLogsForErrors

        protected void checkLogsForErrors​(Predicate<String> acceptableMessagePredicate)
        Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.
        Parameters:
        acceptableMessagePredicate - allows to ignore log entries whose message is accaptable
        Throws:
        AssertionError - if an error is found in the browser logs
      • checkLogsForErrors

        protected void checkLogsForErrors()
        Checks browser's log entries, throws an error for any client-side error and logs any client-side warnings.
        Throws:
        AssertionError - if an error is found in the browser logs
      • waitForDevServer

        protected void waitForDevServer()
        If dev server start in progress wait until it's started. Otherwise return immidiately.
      • blur

        public void blur()
        Calls the blur() function on the current active element of the page, if any.