Class WebDriverBackedEmbeddedBrowser

    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • BROWSER_CLOSE_TIMEOUT_SECS

        private static final int BROWSER_CLOSE_TIMEOUT_SECS
        See Also:
        Constant Field Values
      • filterAttributes

        private final com.google.common.collect.ImmutableSortedSet<String> filterAttributes
      • browser

        private final org.openqa.selenium.WebDriver browser
      • pixelDensity

        private int pixelDensity
      • USE_CDP

        private boolean USE_CDP
        ChromeDeveloperTools are used to fetch event handler information
      • crawlWaitEvent

        private long crawlWaitEvent
      • crawlWaitReload

        private long crawlWaitReload
    • Constructor Detail

      • WebDriverBackedEmbeddedBrowser

        private WebDriverBackedEmbeddedBrowser​(org.openqa.selenium.WebDriver driver)
        Constructor without configuration values.
        Parameters:
        driver - The WebDriver to use.
      • WebDriverBackedEmbeddedBrowser

        private WebDriverBackedEmbeddedBrowser​(org.openqa.selenium.WebDriver driver,
                                               com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                               long crawlWaitReload,
                                               long crawlWaitEvent)
        Constructor.
        Parameters:
        driver - The WebDriver to use.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
      • WebDriverBackedEmbeddedBrowser

        private WebDriverBackedEmbeddedBrowser​(org.openqa.selenium.WebDriver driver,
                                               com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                               long crawlWaitReload,
                                               long crawlWaitEvent,
                                               IgnoreFrameChecker ignoreFrameChecker)
        Constructor.
        Parameters:
        driver - The WebDriver to use.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
        ignoreFrameChecker - the checker used to determine if a certain frame must be ignored.
    • Method Detail

      • withRemoteDriver

        public static WebDriverBackedEmbeddedBrowser withRemoteDriver​(String hubUrl,
                                                                      com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                                                      long crawlWaitEvent,
                                                                      long crawlWaitReload,
                                                                      org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
        Create a RemoteWebDriver backed EmbeddedBrowser.
        Parameters:
        hubUrl - Url of the server.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
        desiredCapabilities - the desired capabilities to use.
        Returns:
        The EmbeddedBrowser.
      • withRemoteDriver

        public static WebDriverBackedEmbeddedBrowser withRemoteDriver​(String hubUrl,
                                                                      com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                                                      long crawlWaitEvent,
                                                                      long crawlWaitReload,
                                                                      IgnoreFrameChecker ignoreFrameChecker,
                                                                      org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
        Create a RemoteWebDriver backed EmbeddedBrowser.
        Parameters:
        hubUrl - Url of the server.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
        ignoreFrameChecker - the checker used to determine if a certain frame must be ignored.
        desiredCapabilities - the desired capabilities to use.
        Returns:
        The EmbeddedBrowser.
      • withDriver

        public static WebDriverBackedEmbeddedBrowser withDriver​(org.openqa.selenium.WebDriver driver,
                                                                com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                                                long crawlWaitEvent,
                                                                long crawlWaitReload)
        Create a WebDriver backed EmbeddedBrowser.
        Parameters:
        driver - The WebDriver to use.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
        Returns:
        The EmbeddedBrowser.
      • withDriver

        public static WebDriverBackedEmbeddedBrowser withDriver​(org.openqa.selenium.WebDriver driver,
                                                                com.google.common.collect.ImmutableSortedSet<String> filterAttributes,
                                                                long crawlWaitEvent,
                                                                long crawlWaitReload,
                                                                IgnoreFrameChecker ignoreFrameChecker)
        Create a WebDriver backed EmbeddedBrowser.
        Parameters:
        driver - The WebDriver to use.
        filterAttributes - the attributes to be filtered from DOM.
        crawlWaitReload - the period to wait after a reload.
        crawlWaitEvent - the period to wait after an event is fired.
        ignoreFrameChecker - the checker used to determine if a certain frame must be ignored.
        Returns:
        The EmbeddedBrowser.
      • withRemoteDriver

        public static WebDriverBackedEmbeddedBrowser withRemoteDriver​(String hubUrl,
                                                                      org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
        Create a RemoteWebDriver backed EmbeddedBrowser.
        Parameters:
        hubUrl - Url of the server.
        desiredCapabilities - the desired capabilities to use.
        Returns:
        The EmbeddedBrowser.
      • buildRemoteWebDriver

        private static org.openqa.selenium.remote.RemoteWebDriver buildRemoteWebDriver​(String hubUrl,
                                                                                       org.openqa.selenium.remote.DesiredCapabilities desiredCapabilities)
        Private used static method for creation of a RemoteWebDriver. Taking care of the default Capabilities and using the HttpCommandExecutor.
        Parameters:
        hubUrl - the url of the hub to use.
        Returns:
        the RemoteWebDriver instance.
      • withDriver

        public static WebDriverBackedEmbeddedBrowser withDriver​(org.openqa.selenium.WebDriver driver)
        Create a WebDriver backed EmbeddedBrowser.
        Parameters:
        driver - The WebDriver to use.
        Returns:
        The EmbeddedBrowser.
      • goToUrl

        public void goToUrl​(URI url)
        Description copied from interface: EmbeddedBrowser
        Opens the url in the browser.
        Specified by:
        goToUrl in interface EmbeddedBrowser
        Parameters:
        url - The URL.
      • handlePopups

        public void handlePopups()
        alert, prompt, and confirm behave as if the OK button is always clicked.
        Specified by:
        handlePopups in interface EmbeddedBrowser
      • fireEventWait

        private boolean fireEventWait​(org.openqa.selenium.WebElement webElement,
                                      Eventable eventable)
                               throws org.openqa.selenium.ElementNotInteractableException,
                                      InterruptedException
        Fires the event and waits for a specified time.
        Parameters:
        webElement - the element to fire event on.
        eventable - The HTML event type (onclick, onmouseover, ...).
        Returns:
        true if firing event is successful.
        Throws:
        InterruptedException - when interrupted during the wait.
        org.openqa.selenium.ElementNotInteractableException
      • quit

        private void quit()
      • toUniformDOM

        private String toUniformDOM​(String html)
        Parameters:
        html - The html string.
        Returns:
        uniform version of dom with predefined attributes stripped
      • filterAttributes

        private String filterAttributes​(String html)
        Filters attributes from the HTML string.
        Parameters:
        html - The HTML to filter.
        Returns:
        The filtered HTML string.
      • input

        public boolean input​(Identification identification,
                             String text)
        Specified by:
        input in interface EmbeddedBrowser
        Parameters:
        identification - The identification object.
        text - The input.
        Returns:
        true if succeeds.
      • fireEventAndWait

        public boolean fireEventAndWait​(Eventable eventable)
                                 throws org.openqa.selenium.ElementNotInteractableException,
                                        org.openqa.selenium.NoSuchElementException,
                                        InterruptedException
        Fires an event on an element using its identification.
        Specified by:
        fireEventAndWait in interface EmbeddedBrowser
        Parameters:
        eventable - The eventable.
        Returns:
        true if it is able to fire the event successfully on the element.
        Throws:
        InterruptedException - when interrupted during the wait.
        org.openqa.selenium.ElementNotInteractableException
        org.openqa.selenium.NoSuchElementException
      • isVisible

        public boolean isVisible​(Identification identification)
        Determines whether the corresponding element is visible.
        Specified by:
        isVisible in interface EmbeddedBrowser
        Parameters:
        identification - The element to search for.
        Returns:
        true if the element is visible
      • getDomTreeWithFrames

        private Document getDomTreeWithFrames()
                                       throws CrawljaxException
        Returns:
        a Document object containing the contents of iframes as well.
        Throws:
        CrawljaxException - if an exception is thrown.
      • getDomTreeWithFrames_GoldStandards

        private Document getDomTreeWithFrames_GoldStandards()
                                                     throws CrawljaxException
        Returns:
        a Document object containing the contents of iframes as well.
        Throws:
        CrawljaxException - if an exception is thrown.
      • appendFrameContent

        private void appendFrameContent​(Element orig,
                                        Document document,
                                        String topFrame)
      • locateFrameAndGetSource

        private void locateFrameAndGetSource​(Document document,
                                             String topFrame,
                                             Element frameElement)
                                      throws org.openqa.selenium.NoSuchFrameException
        Throws:
        org.openqa.selenium.NoSuchFrameException
      • switchToFrame

        private void switchToFrame​(String frameIdentification)
                            throws org.openqa.selenium.NoSuchFrameException
        Throws:
        org.openqa.selenium.NoSuchFrameException
      • getInputWithRandomValue

        public FormInput getInputWithRandomValue​(FormInput input)
        Specified by:
        getInputWithRandomValue in interface EmbeddedBrowser
        Parameters:
        input - the input to be filled.
        Returns:
        FormInput with random value assigned if possible. If no values were set it returns null
      • setRandomValues

        private void setRandomValues​(FormInput input,
                                     org.openqa.selenium.WebElement webElement,
                                     Set<InputValue> values)
      • getFrameDom

        public String getFrameDom​(String iframeIdentification)
        Specified by:
        getFrameDom in interface EmbeddedBrowser
        Parameters:
        iframeIdentification - the iframe's name or id.
        Returns:
        the DOM string of the corresponding iframe.
      • elementExists

        public boolean elementExists​(Identification identification)
        Specified by:
        elementExists in interface EmbeddedBrowser
        Parameters:
        identification - the identification of the element.
        Returns:
        true if the element can be found in the DOM tree.
      • getWebElement

        public org.openqa.selenium.WebElement getWebElement​(Identification identification)
        Specified by:
        getWebElement in interface EmbeddedBrowser
        Parameters:
        identification - the identification of the element.
        Returns:
        the found element.
      • getWebDriver

        public org.openqa.selenium.WebDriver getWebDriver()
        Specified by:
        getWebDriver in interface EmbeddedBrowser
        Returns:
        The selenium web driver.
      • getCrawlWaitEvent

        private long getCrawlWaitEvent()
        Returns:
        the period to wait after an event.
      • getFilterAttributes

        private com.google.common.collect.ImmutableSortedSet<String> getFilterAttributes()
        Returns:
        the list of attributes to be filtered from DOM.
      • getCrawlWaitReload

        private long getCrawlWaitReload()
        Returns:
        the period to wait after a reload.
      • takeScreenShotOnBrowser

        private <T> T takeScreenShotOnBrowser​(org.openqa.selenium.WebDriver driver,
                                              org.openqa.selenium.OutputType<T> outType)
                                       throws CrawljaxException
        Throws:
        CrawljaxException
      • removeCanvasGeneratedByFirefoxDriverForScreenshots

        private void removeCanvasGeneratedByFirefoxDriverForScreenshots()
      • getBrowser

        public org.openqa.selenium.WebDriver getBrowser()
        Returns:
        the WebDriver used as an EmbeddedBrowser.
      • exceptionIsConnectionException

        private boolean exceptionIsConnectionException​(org.openqa.selenium.WebDriverException exception)
      • wrapWebDriverExceptionIfConnectionException

        private RuntimeException wrapWebDriverExceptionIfConnectionException​(org.openqa.selenium.WebDriverException exception)
      • throwIfConnectionException

        private void throwIfConnectionException​(org.openqa.selenium.WebDriverException exception)
      • throwIfNotInteractableException

        private void throwIfNotInteractableException​(org.openqa.selenium.WebDriverException exception)
      • exceptionIsInteractableException

        private boolean exceptionIsInteractableException​(org.openqa.selenium.WebDriverException exception)
      • setPixelDensity

        public void setPixelDensity​(int pixelDensity)
      • isUSE_CDP

        public boolean isUSE_CDP()
      • setUSE_CDP

        public void setUSE_CDP​(boolean USE_CDP)