Class WebDriverEx


  • public class WebDriverEx
    extends Object
    Provides additional actions over standard Selenium Remote Web Driver.

    W3C Standards

    • Field Detail

      • 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.
    • Constructor Detail

      • WebDriverEx

        public WebDriverEx​(org.openqa.selenium.WebDriver driver,
                           org.openqa.selenium.Capabilities originalCapabilities)
        Parameters:
        driver - the driver to wrap
        originalCapabilities - the original capabilities
    • Method Detail

      • descriptionOf

        public static String descriptionOf​(org.openqa.selenium.WebElement element)
        Parameters:
        element - an element
        Returns:
        description of specified element
      • 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 dispatch
        element - 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