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 TypeMethodDescriptionvoidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) Sets test name while using SauceLabs integration, injectsWebDriverandCapabilitiesreferences and sets the driver for this test instance.org.junit.jupiter.api.extension.ConditionEvaluationResultevaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context) org.openqa.selenium.remote.DesiredCapabilitiesorg.openqa.selenium.WebDriverReturns activeWebDriverthat used by this test case.protected StringgetHubHostname(Class<?> testClass) Returns the hostname of the hub where test is to be run on.protected StringReturns the complete URL of the hub where the tests will be run on.protected BrowsergetRunLocallyBrowser(Class<?> testClass) protected StringgetRunLocallyBrowserVersion(Class<?> testClass) protected RunOnHubgetRunOnHub(Class<?> testClass) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) voidsetDriver(org.openqa.selenium.WebDriver driver) Sets the activeWebDriverthat is used by this test casebooleansupportsParameter(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 activeWebDriverthat is used by this test case- Parameters:
driver- The WebDriver instance to set.
-
getDriver
public org.openqa.selenium.WebDriver getDriver()Returns activeWebDriverthat used by this test case. -
evaluateExecutionCondition
public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
evaluateExecutionConditionin 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.hubHostnamesystem parameter or the host defined using aRunOnHubannotation.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
WebDriverandCapabilitiesreferences and sets the driver for this test instance. UsesSetupDriver.setupRemoteDriver(String)orSetupDriver.setupLocalDriver(Browser)according to the annotations found in current test case.RunOnHubannotation can be used on the test case class to define a test hub's hostname for the driver to connect to it.
RunLocallyannotation can be used on the test case class to force the driver to connect to localhost (RunLocallyannotation overridesRunOnHubannotation).- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception- if unable to instantiateWebDriver
-
getRunOnHub
-
getRunLocallyBrowser
- Returns:
- Browser value of the
RunLocallyannotation of current Class, or null if annotation is not present.
-
getRunLocallyBrowserVersion
- Returns:
- Version value of the
RunLocallyannotation 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:
supportsParameterin 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:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-