public final class WebDriverCache extends Object
Static utility testing class to keep a Selenium Web Driver open between tests using the same thread. This is to prevent the expensive WebDriver creation occurring multiple times per test suite.
WebDriver implementations are not thread-safe, so the drivers opened by this class will be separated from other threads via a ThreadLocal.
Multiple concurrent instances of the same driver type can be created using a different driver id.
This class will clean up open drivers when the JVM terminates.
| Modifier and Type | Method and Description |
|---|---|
static void |
closeDriver(WebDriverType driverType)
Close the driver of the given driver type and default driver id.
|
static void |
closeDriver(WebDriverType driverType,
String driverId)
Close the driver of the given type and driver id.
|
static void |
closeDriversForAllThreads()
Close all drivers for all threads
Warning: this method will not clear out the ThreadLocals for any
thread.
|
static void |
closeDriversForCurrentThread()
Close all drivers created by the current thread.
|
static <T extends org.openqa.selenium.WebDriver> |
getDriver(WebDriverType<T> driverType)
Get or create the driver for the given driver type.
|
static <T extends org.openqa.selenium.WebDriver> |
getDriver(WebDriverType<T> driverType,
String driverId)
Get or create the driver for the given driver type and unique driver id.
|
static <T extends org.openqa.selenium.WebDriver> |
openDriver(WebDriverType<T> driverType)
Open a new instance of the given driver type
Will close and replace any existing driver with the same type and default
driver id.
|
static <T extends org.openqa.selenium.WebDriver> |
openDriver(WebDriverType<T> driverType,
SeleniumWComponentsWebDriver<T> driver,
String driverId)
Register the given driver implementation to be shared with this class
using the given type and driver Id
Will close and replace any existing driver with the same type and driver
id.
|
static <T extends org.openqa.selenium.WebDriver> |
openDriver(WebDriverType<T> driverType,
String driverId)
Open a new instance of the given driver type with a unique driver id
Will close and replace any existing driver with the same type and driver
id.
|
public static <T extends org.openqa.selenium.WebDriver> SeleniumWComponentsWebDriver<T> getDriver(WebDriverType<T> driverType)
T - the type of the WebDriver.driverType - the WebDriver type wrapper.public static <T extends org.openqa.selenium.WebDriver> SeleniumWComponentsWebDriver<T> getDriver(WebDriverType<T> driverType, String driverId)
T - the type of the WebDriver.driverType - the WebDriver type wrapper.driverId - the unique identifier for this driver implementation.public static <T extends org.openqa.selenium.WebDriver> SeleniumWComponentsWebDriver<T> openDriver(WebDriverType<T> driverType)
Open a new instance of the given driver type
Will close and replace any existing driver with the same type and default driver id.
T - the type of the WebDriver.driverType - the WebDriver type wrapper.public static <T extends org.openqa.selenium.WebDriver> SeleniumWComponentsWebDriver<T> openDriver(WebDriverType<T> driverType, String driverId)
Open a new instance of the given driver type with a unique driver id
Will close and replace any existing driver with the same type and driver id.
T - the type of the WebDriver.driverType - the WebDriver type wrapper.driverId - the unique identifier for this driver implementation.public static <T extends org.openqa.selenium.WebDriver> SeleniumWComponentsWebDriver<T> openDriver(WebDriverType<T> driverType, SeleniumWComponentsWebDriver<T> driver, String driverId)
Register the given driver implementation to be shared with this class using the given type and driver Id
Will close and replace any existing driver with the same type and driver id.
T - the type of the WebDriver.driverType - the WebDriver type wrapper.driver - the WebDriver implementation to use.driverId - the unique identifier for this driver implementation.public static void closeDriversForCurrentThread()
public static void closeDriversForAllThreads()
Close all drivers for all threads
Warning: this method will not clear out the ThreadLocals for any thread. Any thread reusing this class after this method was invoked must manually close and reopen all driver handles.
public static void closeDriver(WebDriverType driverType)
driverType - the type of the driver to close.public static void closeDriver(WebDriverType driverType, String driverId)
driverType - the type of the driver to close.driverId - the unique driver id of the driver to closeCopyright © 2016. All rights reserved.