Class WebDriverEx
- java.lang.Object
-
- dev.aherscu.qa.jgiven.commons.utils.WebDriverEx
-
public class WebDriverEx extends Object
Provides additional actions over standard Selenium Remote Web Driver.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WebDriverEx.Event
Represents a DOM Event.static class
WebDriverEx.MouseEvent
Represents a DOM MouseEvent.static class
WebDriverEx.PointerEvent
Represents a DOM Pointer Event.static class
WebDriverEx.UIEvent
Represents a DOM UIEvent.
-
Field Summary
Fields Modifier and Type Field Description static String
NATIVE_APP_CONTEXT
The application native context id.org.openqa.selenium.Capabilities
originalCapabilities
Original capabilities used to initiate this web driver; might be null.static com.google.common.collect.Multimap<SessionName,WebDriverSessionInfo>
remoteSessions
Maps tests to remote Web Driver sessions, if there were any.
-
Constructor Summary
Constructors Constructor Description WebDriverEx(org.openqa.selenium.WebDriver driver, org.openqa.selenium.Capabilities originalCapabilities)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends org.openqa.selenium.WebElement>
io.appium.java_client.android.AndroidDriverasAndroid()
Casts an WebDriver into an AndroidDriver.org.openqa.selenium.WebDriver
asGeneric()
<T extends org.openqa.selenium.WebElement>
io.appium.java_client.ios.IOSDriverasIOS()
org.openqa.selenium.JavascriptExecutor
asJavaScriptExecutor()
Casts an WebDriver into a JavascriptExecutor.org.openqa.selenium.remote.RemoteWebDriver
asRemote()
Casts an WebDriver into a RemoteWebDriver.io.appium.java_client.windows.WindowsDriver
asWindows()
Casts an WebDriver into a WindowsDriver.static String
descriptionOf(org.openqa.selenium.WebElement element)
boolean
dispatch(WebDriverEx.Event event, org.openqa.selenium.WebElement element)
Dispatches and event to a target element per DOM Level4void
forceClick(org.openqa.selenium.WebElement element)
Bypasses Selenium by executing the click via JavaScript, thus enabling clicking of obscured or otherwise hidden elements.static WebDriverEx
from(org.openqa.selenium.Capabilities capabilities)
Attempts to initialize a Web driver with specified capabilities.boolean
is(Class<?> type)
void
safelyQuit()
Quits the driver swallowing exceptions.org.openqa.selenium.WebElement
scrollIntoView(org.openqa.selenium.WebElement element)
Scrolls an Element into View per CSSOM View Module Element Interface Extensionsstatic Iterable<WebDriverSessionInfo>
sessionInfos()
String
toString()
String
webContextIdentifier()
Retrieves Web context identifier of running mobile application.static org.openqa.selenium.WebDriver
webDriverFor(org.openqa.selenium.Capabilities capabilities)
Initializes a WebDriver for specified capabilities.
-
-
-
Field Detail
-
NATIVE_APP_CONTEXT
public static final String NATIVE_APP_CONTEXT
The application native context id.- See Also:
- Constant Field Values
-
remoteSessions
public static final com.google.common.collect.Multimap<SessionName,WebDriverSessionInfo> remoteSessions
Maps tests to remote Web Driver sessions, if there were any. Uses a synchronized version since it may be accessed from multiple threads.
-
originalCapabilities
public final org.openqa.selenium.Capabilities originalCapabilities
Original capabilities used to initiate this web driver; might be null.
-
-
Method Detail
-
descriptionOf
public static String descriptionOf(org.openqa.selenium.WebElement element)
- Parameters:
element
- an element- Returns:
- description of specified element
-
from
public static WebDriverEx from(org.openqa.selenium.Capabilities capabilities)
Attempts to initialize a Web driver with specified capabilities.In addition, adds the Remote Web Driver session identifier to
remoteSessions
mapped to name of test as defined byConfigurableScenarioTest.beforeClassInitializeSession()
orConfigurableScenarioTest.beforeMethodInitializeSession(java.lang.reflect.Method, java.lang.Object[])
- Parameters:
capabilities
- the capabilities; might be null; the capabilities may includename
for registering this web driver for some sort of status reporting mechanism- Returns:
- the initialized driver, or null if
DryRunAspect.dryRun
- Throws:
RuntimeException
- or derivative, if the initialization failed
-
sessionInfos
public static Iterable<WebDriverSessionInfo> sessionInfos()
- Returns:
- the registered Web Driver session informations for current test
method, including those registered during
@BeforeClass
-
webDriverFor
public static org.openqa.selenium.WebDriver webDriverFor(org.openqa.selenium.Capabilities capabilities)
Initializes a WebDriver for specified capabilities.- Parameters:
capabilities
- the capabilities- Returns:
- the Web Driver
-
asAndroid
public <T extends org.openqa.selenium.WebElement> io.appium.java_client.android.AndroidDriver asAndroid()
Casts an WebDriver into an AndroidDriver.- Type Parameters:
T
- type of WebElement- Returns:
- the AndroidDriver interface
- Throws:
ClassCastException
- if the driver is not of AndroidDriver type
-
asGeneric
public org.openqa.selenium.WebDriver asGeneric()
-
asIOS
public <T extends org.openqa.selenium.WebElement> io.appium.java_client.ios.IOSDriver asIOS()
-
asJavaScriptExecutor
public org.openqa.selenium.JavascriptExecutor asJavaScriptExecutor()
Casts an WebDriver into a JavascriptExecutor.- Returns:
- the JavascriptExecutor interface
- Throws:
ClassCastException
- if JavaScript not supported
-
asRemote
public org.openqa.selenium.remote.RemoteWebDriver asRemote()
Casts an WebDriver into a RemoteWebDriver.- Returns:
- the RemoteWebDriver interface
- Throws:
ClassCastException
- if the driver is not of RemoteWebDriver type
-
asWindows
public io.appium.java_client.windows.WindowsDriver asWindows()
Casts an WebDriver into a WindowsDriver.- Returns:
- the WindowsDriver interface
- Throws:
ClassCastException
- if the driver is not of WindowsDriver type
-
dispatch
public boolean dispatch(WebDriverEx.Event event, org.openqa.selenium.WebElement element)
Dispatches and event to a target element per DOM Level4- Parameters:
event
- the event to dispatchelement
- the element- Returns:
- status of event per specification
- Throws:
UnsupportedOperationException
- if the operation fails
-
forceClick
public void forceClick(org.openqa.selenium.WebElement element)
Bypasses Selenium by executing the click via JavaScript, thus enabling clicking of obscured or otherwise hidden elements.- Parameters:
element
- the element to click on
-
is
public boolean is(Class<?> type)
-
safelyQuit
public void safelyQuit()
Quits the driver swallowing exceptions.
-
scrollIntoView
public org.openqa.selenium.WebElement scrollIntoView(org.openqa.selenium.WebElement element)
Scrolls an Element into View per CSSOM View Module Element Interface Extensions- Parameters:
element
- the element- Returns:
- the element
-
webContextIdentifier
public String webContextIdentifier()
Retrieves Web context identifier of running mobile application.- Returns:
- the identifier of first Web context
- Throws:
TestRuntimeException
- if no Web context/view was found
-
-