com.vaadin.testbench.

Class TestBenchTestCase

java.lang.Object
com.vaadin.testbench.TestBenchTestCase

All Implemented Interfaces:

HasDriver, HasElementQuery, HasSearchContext, HasTestBenchCommandExecutor

Direct Known Subclasses:

ParallelTest

public abstract class TestBenchTestCase extends Object implements HasDriver, HasTestBenchCommandExecutor, HasElementQuery

A superclass with some helpers to aid TestBench developers.

  • Field Details

    • maxAttempts

      public RetryRule maxAttempts

      Specifies retry count, which is used to run same test several times. Can be changed by setting "com.vaadin.testbench.Parameters.maxAttempts" system property. Default: 1

    • driver

      protected org.openqa.selenium.WebDriver driver
  • Constructor Details

    • TestBenchTestCase

      public TestBenchTestCase()
  • Method Details

    • testBench

      public TestBenchCommands testBench()

      Convenience method the return TestBenchCommands for the default WebDriver instance.

      Returns:

      The driver cast to a TestBenchCommands instance.

    • concatUrl

      protected String concatUrl(String baseUrl, String uri)

      Combines a base URL with an URI to create a final URL. This removes possible double slashes if the base URL ends with a slash and the URI begins with a slash.

      Parameters:

      baseUrl - the base URL

      uri - the URI

      Returns:

      the URL resulting from the combination of base URL and URI

    • getDriver

      public org.openqa.selenium.WebDriver getDriver()

      Returns the WebDriver instance previously specified by setDriver(org.openqa.selenium.WebDriver), or (if the previously provided WebDriver instance was not already a TestBenchDriverProxy instance) a TestBenchDriverProxy that wraps that driver.

      Specified by:

      getDriver in interface HasDriver

      Returns:

      the active WebDriver instance

    • setDriver

      public void setDriver(org.openqa.selenium.WebDriver driver)

      Sets the active WebDriver that is used by this this case

      Parameters:

      driver - The WebDriver instance to set.

    • getContext

      public org.openqa.selenium.SearchContext getContext()

      Description copied from interface: HasSearchContext

      Get a reference or a new instance of the SearchContext applicable to this class

      Specified by:

      getContext in interface HasSearchContext

      Returns:

      a SearchContext instance

    • getCommandExecutor

      public TestBenchCommandExecutor getCommandExecutor()

      Description copied from interface: HasTestBenchCommandExecutor

      Return a reference to the related TestBenchCommandExecutor instance.

      Specified by:

      getCommandExecutor in interface HasTestBenchCommandExecutor

      Returns:

      the TestBenchCommandExecutor instance

    • findElement

      public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
    • findElements

      public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
    • wrap

      public <T extends TestBenchElement> T wrap(Class<T> elementType, org.openqa.selenium.WebElement element)

      Decorates the element with the specified Element type, making it possible to use component-specific API on elements found using standard Selenium API.

      Type Parameters:

      T - the type of the TestBenchElement to return

      Parameters:

      elementType - The type (class) containing the API to decorate with

      element - The element instance to decorate

      Returns:

      The element wrapped in an instance of the specified element type.

    • executeScript

      protected Object executeScript(String script, Object... args)

      Executes the given JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.

      This method wraps any returned WebElement as TestBenchElement.

      Parameters:

      script - the script to execute

      args - the arguments, available in the script as arguments[0]...arguments[N]

      Returns:

      whatever JavascriptExecutor.executeScript(String, Object...) returns

      Throws:

      UnsupportedOperationException - if the underlying driver does not support JavaScript execution

      See Also:

      • JavascriptExecutor.executeScript(String, Object...)

    • waitUntil

      protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition, long timeoutInSeconds)

      Waits the given number of seconds for the given condition to become neither null nor false. NotFoundExceptions are ignored by default.

      Use e.g. as waitUntil(ExpectedConditions.presenceOfElementLocated(by), 10);

      Type Parameters:

      T - The return type of the ExpectedCondition and this method

      Parameters:

      condition - Models a condition that might reasonably be expected to eventually evaluate to something that is neither null nor false.

      timeoutInSeconds - The timeout in seconds for the wait.

      Returns:

      The condition's return value if it returned something different from null or false before the timeout expired.

      Throws:

      org.openqa.selenium.TimeoutException - If the timeout expires.

      See Also:

      • FluentWait.until(java.util.function.Function<? super T, V>)
      • ExpectedCondition

    • waitUntil

      protected <T> T waitUntil(org.openqa.selenium.support.ui.ExpectedCondition<T> condition)

      Waits up to 10 seconds for the given condition to become neither null nor false. NotFoundExceptions are ignored by default.

      Use e.g. as waitUntil(ExpectedConditions.presenceOfElementLocated(by));

      Type Parameters:

      T - The return type of the ExpectedCondition and this method

      Parameters:

      condition - Models a condition that might reasonably be expected to eventually evaluate to something that is neither null nor false.

      Returns:

      The condition's return value if it returned something different from null or false before the timeout expired.

      Throws:

      org.openqa.selenium.TimeoutException - If 10 seconds passed.

      See Also:

      • FluentWait.until(java.util.function.Function<? super T, V>)
      • ExpectedCondition