com.vaadin.testbench.browser.

Class BrowserExtension

java.lang.Object
com.vaadin.testbench.browser.BrowserExtension

All Implemented Interfaces:

HasDriver, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.ExecutionCondition, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver

public class BrowserExtension extends Object implements org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.ExecutionCondition, HasDriver, org.junit.jupiter.api.extension.ParameterResolver

TestBench Extension that provides WebDriver configuration and startup according to given test configuration and desired capabilities.

See beforeEach(ExtensionContext) for more detailed information about test preparation.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.openqa.selenium.WebDriver
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    BrowserExtension(org.openqa.selenium.Capabilities capabilities)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)

    Sets test name while using SauceLabs integration, injects WebDriver and Capabilities references and sets the driver for this test instance.

    org.junit.jupiter.api.extension.ConditionEvaluationResult
    evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)
     
    org.openqa.selenium.remote.DesiredCapabilities
     
    org.openqa.selenium.WebDriver

    Returns active WebDriver that used by this test case.

    protected String
    getHubHostname(Class<?> testClass)

    Returns the hostname of the hub where test is to be run on.

    protected String
    getHubURL(Class<?> testClass)

    Returns the complete URL of the hub where the tests will be run on.

    protected Browser
     
    protected String
     
    protected RunOnHub
    getRunOnHub(Class<?> testClass)
     
    resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     
    void
    setDriver(org.openqa.selenium.WebDriver driver)

    Sets the active WebDriver that is used by this test case

    boolean
    supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • driver

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

    • BrowserExtension

      public BrowserExtension(org.openqa.selenium.Capabilities capabilities)
    • BrowserExtension

      public BrowserExtension()
  • Method Details

    • setDriver

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

      Sets the active WebDriver that is used by this test case

      Parameters:

      driver - The WebDriver instance to set.

    • getDriver

      public org.openqa.selenium.WebDriver getDriver()

      Returns active WebDriver that used by this test case.

      Specified by:

      getDriver in interface HasDriver

      Returns:

      currently used WebDriver

    • evaluateExecutionCondition

      public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context)

      Specified by:

      evaluateExecutionCondition in interface org.junit.jupiter.api.extension.ExecutionCondition

    • getHubURL

      protected String getHubURL(Class<?> testClass)

      Returns the complete URL of the hub where the tests will be run on. Used by beforeEach(ExtensionContext) ()}, for the creation of the WebDriver.

      This method uses getHubHostname(Class) to build the complete address of the Hub. Override in order to define a different hub address.

      You can provide sauce.user and sauce.sauceAccessKey system properties or SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables to run the tests in Sauce Labs. If both system property and environment variable is defined, system property is prioritised.

      Returns:

      the complete URL of the hub where the tests will be run on. Used by beforeEach(ExtensionContext) ()}, for the creation of the WebDriver.

    • getHubHostname

      protected String getHubHostname(Class<?> testClass)

      Returns the hostname of the hub where test is to be run on. If unit test is annotated by RunLocally, this method returns localhost. Otherwise, it will return the host defined by the com.vaadin.testbench.Parameters.hubHostname system parameter or the host defined using a RunOnHub annotation.

      This method is used by getHubURL(Class) to get the full URL of the hub to run tests on.

      Returns:

      the hostname of the hub where test is to be run on.

    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception

      Sets test name while using SauceLabs integration, injects WebDriver and Capabilities references and sets the driver for this test instance. Uses SetupDriver.setupRemoteDriver(String) or SetupDriver.setupLocalDriver(Browser) according to the annotations found in current test case.

      RunOnHub annotation can be used on the test case class to define a test hub's hostname for the driver to connect to it.
      RunLocally annotation can be used on the test case class to force the driver to connect to localhost (RunLocally annotation overrides RunOnHub annotation).

      Specified by:

      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback

      Throws:

      Exception - if unable to instantiate WebDriver

    • getRunOnHub

      protected RunOnHub getRunOnHub(Class<?> testClass)

      Parameters:

      testClass - the test class to get the RunOnHub annotation from

      Returns:

      Value of the RunOnHub annotation of passed Class, or null if annotation is not present.

    • getRunLocallyBrowser

      protected Browser getRunLocallyBrowser(Class<?> testClass)

      Returns:

      Browser value of the RunLocally annotation of current Class, or null if annotation is not present.

    • getRunLocallyBrowserVersion

      protected String getRunLocallyBrowserVersion(Class<?> testClass)

      Returns:

      Version value of the RunLocally annotation of current Class, or empty String if annotation is not present.

    • getDesiredCapabilities

      public org.openqa.selenium.remote.DesiredCapabilities getDesiredCapabilities()

      Returns:

      Current instance of DesiredCapabilities.

    • supportsParameter

      public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException

      Specified by:

      supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver

      Throws:

      org.junit.jupiter.api.extension.ParameterResolutionException

    • resolveParameter

      public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException

      Specified by:

      resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver

      Throws:

      org.junit.jupiter.api.extension.ParameterResolutionException