com.vaadin.testbench.browser.
Class 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
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context) Sets test name while using SauceLabs integration, injects
WebDriver
andCapabilities
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
Returns the complete URL of the hub where the tests will be run on.
protected Browser
getRunLocallyBrowser
(Class<?> testClass) protected String
getRunLocallyBrowserVersion
(Class<?> testClass) 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 caseboolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
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 caseParameters:
driver
- The WebDriver instance to set. -
getDriver
public org.openqa.selenium.WebDriver getDriver()Returns active
WebDriver
that used by this test case. -
evaluateExecutionCondition
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context) Specified by:
evaluateExecutionCondition
in interfaceorg.junit.jupiter.api.extension.ExecutionCondition
-
getHubURL
Returns the complete URL of the hub where the tests will be run on. Used by
beforeEach(ExtensionContext)
()}, for the creation of theWebDriver
.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 theWebDriver
. -
getHubHostname
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 thecom.vaadin.testbench.Parameters.hubHostname
system parameter or the host defined using aRunOnHub
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
Sets test name while using SauceLabs integration, injects
WebDriver
andCapabilities
references and sets the driver for this test instance. UsesSetupDriver.setupRemoteDriver(String)
orSetupDriver.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 overridesRunOnHub
annotation).Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
Throws:
Exception
- if unable to instantiateWebDriver
-
getRunOnHub
-
getRunLocallyBrowser
Returns:
Browser value of the
RunLocally
annotation of current Class, or null if annotation is not present. -
getRunLocallyBrowserVersion
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 interfaceorg.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 interfaceorg.junit.jupiter.api.extension.ParameterResolver
Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-