Class CapybaraPortingLayerImpl

    • Constructor Summary

      Constructors 
      Constructor Description
      CapybaraPortingLayerImpl​(com.google.inject.Injector injector)
      Some subtypes are constructed via Guice, in which case injection is done by outside this class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      List<org.openqa.selenium.WebElement> all​(org.openqa.selenium.By selector)
      Finds all the elements that match the selector.
      void blur​(org.openqa.selenium.WebElement e)
      Sends a blur event to the provided element
      void check​(String locator)
      Checks the specified checkbox.
      void check​(org.openqa.selenium.WebElement e)
      Checks the checkbox.
      void check​(org.openqa.selenium.WebElement e, boolean state)
      Sets the state of the checkbox to the specified value.
      org.openqa.selenium.WebElement choose​(String locator)
      Select radio button by its name, id, or label text.
      void clickButton​(String text)  
      void clickLink​(String locator)  
      void confirmAlert​(int timeout)
      Confirms an alert giving it some time to appear
      void elasticSleep​(long ms)  
      Object executeScript​(String javaScript, Object... args)
      Executes JavaScript.
      void fillIn​(String formFieldName, Object value)  
      org.openqa.selenium.WebElement find​(org.openqa.selenium.By selector)
      Returns the first visible element that matches the selector.
      protected <T> T findCaption​(Class<?> type, Function<String,​T> finder)  
      protected <T> T findCaption​(Class<?> type, CapybaraPortingLayerImpl.Finder<T> call)  
      org.openqa.selenium.WebElement findIfNotVisible​(org.openqa.selenium.By selector)
      Returns the first element that matches the selector even if not visible.
      String getCurrentUrl()
      Get a string representing the current URL that the browser is looking at.
      String getCurrentUrlWithFragment()
      Get a string representing the current URL with fragment part that the browser is looking at.
      org.openqa.selenium.WebElement getElement​(org.openqa.selenium.By selector)
      Works like find(org.openqa.selenium.By) but instead of throwing an exception, this method returns null.
      static String getPageContent​(org.openqa.selenium.WebDriver driver)
      Get visible text on the page.
      String getPageSource()
      Get all text of the page including markup.
      static String getPageSource​(org.openqa.selenium.WebDriver driver)  
      String getPath​(org.openqa.selenium.WebElement e)
      Resolves the path attribute from the element, handling radio buttons and checkboxes.
      void handleAlert​(Consumer<org.openqa.selenium.Alert> action)  
      protected static boolean isHiddenOrStale​(org.openqa.selenium.WebElement we)  
      protected static boolean isStale​(org.openqa.selenium.WebElement element)
      Returns true if the webElement is stale (that is accessing it would cause a StaleElementReferenceException to be thrown
      org.openqa.selenium.WebElement last​(org.openqa.selenium.By selector)
      Picks up the last visible element that matches given selector.
      org.openqa.selenium.WebElement lastIfNotVisible​(org.openqa.selenium.By selector)
      Picks up the last visible element that matches given selector.
      protected <T> T newInstance​(Class<T> type, Object... args)
      Finds matching constructor and invoke it.
      Resource resource​(String path)
      Obtains a resource in a wrapper.
      void runThenConfirmAlert​(Runnable runnable)  
      void runThenConfirmAlert​(Runnable runnable, int timeout)
      Do something that triggers an alert then giving it some time to appear
      void runThenHandleAlert​(Runnable runnable, Consumer<org.openqa.selenium.Alert> action)  
      void runThenHandleAlert​(Runnable runnable, Consumer<org.openqa.selenium.Alert> action, int timeoutSeconds)  
      void runThenHandleDialog​(Runnable runnable)
      Helper to execute something that shows a confirmation dialog with a "Yes" button or a classical browser confirm Executes the runnable, wait for "Yes" button of the modal dialog and presses the "Yes" button" In case the runnable opens a classical browse dialog this is accepted.
      void sleep​(long ms)
      Thread.sleep that masks exception.
      protected org.openqa.selenium.WebDriver visit​(URL url)
      Navigates the browser to the page.
      Wait<CapybaraPortingLayer> waitFor()  
      org.openqa.selenium.WebElement waitFor​(org.openqa.selenium.By selector)
      Wait until the element that matches the given selector appears.
      org.openqa.selenium.WebElement waitFor​(org.openqa.selenium.By selector, int timeoutSec)
      Wait until the element that matches the given selector appears.
      <MatcherT,​SubjectT extends MatcherT>
      void
      waitFor​(SubjectT item, org.hamcrest.Matcher<MatcherT> matcher, int timeout)
      Wait until a matcher matches.
      <T> Wait<T> waitFor​(T subject)
      Default waiting object configured with default timing.
      <T> T waitForCond​(Callable<T> block)
      Deprecated.
      <T> T waitForCond​(Callable<T> block, int timeoutSec)
      Deprecated.
    • Field Detail

      • driver

        @Inject
        protected org.openqa.selenium.WebDriver driver
        WebDriver that subtypes use to talk to the server.
      • injector

        @Inject
        public com.google.inject.Injector injector
        Access to the rest of the world.
    • Constructor Detail

      • CapybaraPortingLayerImpl

        public CapybaraPortingLayerImpl​(com.google.inject.Injector injector)
        Some subtypes are constructed via Guice, in which case injection is done by outside this class. The injector parameter should be null for that case.

        Some subtypes are constructed programmatically. In that case, non-null injector must be supplied.

    • Method Detail

      • getCurrentUrl

        public String getCurrentUrl()
        Get a string representing the current URL that the browser is looking at.
        Returns:
        The URL of the page currently loaded in the browser
      • getCurrentUrlWithFragment

        public String getCurrentUrlWithFragment()
        Get a string representing the current URL with fragment part that the browser is looking at.
        Returns:
        The URL with fragment part of the page currently loaded in the browser.
      • visit

        protected final org.openqa.selenium.WebDriver visit​(URL url)
        Navigates the browser to the page.
        Parameters:
        url - URL relative to the context path of Jenkins, such as "/about" or "/job/foo/configure".
      • choose

        public org.openqa.selenium.WebElement choose​(String locator)
        Select radio button by its name, id, or label text.
        Specified by:
        choose in interface CapybaraPortingLayer
      • waitFor

        public <T> Wait<T> waitFor​(T subject)
        Default waiting object configured with default timing.
        Specified by:
        waitFor in interface CapybaraPortingLayer
        See Also:
        Wait
      • waitFor

        public org.openqa.selenium.WebElement waitFor​(org.openqa.selenium.By selector,
                                                      int timeoutSec)
        Wait until the element that matches the given selector appears.
        Specified by:
        waitFor in interface CapybaraPortingLayer
      • waitFor

        public org.openqa.selenium.WebElement waitFor​(org.openqa.selenium.By selector)
        Description copied from interface: CapybaraPortingLayer
        Wait until the element that matches the given selector appears.
        Specified by:
        waitFor in interface CapybaraPortingLayer
      • waitForCond

        @Deprecated
        public <T> T waitForCond​(Callable<T> block,
                                 int timeoutSec)
        Deprecated.
        Repeated evaluate the given predicate until it returns true.

        If it times out, an exception will be thrown.

        Specified by:
        waitForCond in interface CapybaraPortingLayer
        timeoutSec - 0 if left to the default value
      • waitFor

        public <MatcherT,​SubjectT extends MatcherT> void waitFor​(SubjectT item,
                                                                       org.hamcrest.Matcher<MatcherT> matcher,
                                                                       int timeout)
        Description copied from interface: CapybaraPortingLayer
        Wait until a matcher matches.
        Specified by:
        waitFor in interface CapybaraPortingLayer
      • find

        public org.openqa.selenium.WebElement find​(org.openqa.selenium.By selector)
        Returns the first visible element that matches the selector.
        Specified by:
        find in interface CapybaraPortingLayer
        Throws:
        org.openqa.selenium.NoSuchElementException - if the element is not found.
        See Also:
        if you don't want to see an exception
      • findIfNotVisible

        public org.openqa.selenium.WebElement findIfNotVisible​(org.openqa.selenium.By selector)
        Returns the first element that matches the selector even if not visible.
        Specified by:
        findIfNotVisible in interface CapybaraPortingLayer
        Throws:
        org.openqa.selenium.NoSuchElementException - if the element is not found.
        See Also:
        if you don't want to see an exception
      • check

        public void check​(org.openqa.selenium.WebElement e)
        Checks the checkbox.
        Specified by:
        check in interface CapybaraPortingLayer
      • check

        public void check​(org.openqa.selenium.WebElement e,
                          boolean state)
        Sets the state of the checkbox to the specified value.
        Specified by:
        check in interface CapybaraPortingLayer
      • getPath

        @CheckForNull
        public String getPath​(org.openqa.selenium.WebElement e)
        Resolves the path attribute from the element, handling radio buttons and checkboxes.
        Parameters:
        e - the element to retrieve the path from.
        Returns:
        the path attribute if it exists.
      • blur

        public void blur​(org.openqa.selenium.WebElement e)
        Sends a blur event to the provided element
        Specified by:
        blur in interface CapybaraPortingLayer
      • all

        public List<org.openqa.selenium.WebElement> all​(org.openqa.selenium.By selector)
        Finds all the elements that match the selector.

        Note that this method inherits the same restriction of the WebDriver.findElements(org.openqa.selenium.By), in that its execution is not synchronized with the JavaScript execution of the browser.

        For example, if you click something that's expected to populate additional DOM elements, and then call all() to find them, then all() can execute before those additional DOM elements are populated, thereby failing to find the elements you are looking for.

        In contrast, find(org.openqa.selenium.By) do not have this problem, because it waits until the element that matches the criteria appears.

        So if you are using this method, think carefully. Perhaps you can use find(org.openqa.selenium.By) to achieve what you are looking for (by making the query more specific), or perhaps you can combine this with waitForCond(java.util.concurrent.Callable) so that if you don't find the elements you are looking for in the list, you'll retry.

        Specified by:
        all in interface CapybaraPortingLayer
      • last

        public org.openqa.selenium.WebElement last​(org.openqa.selenium.By selector)
        Picks up the last visible element that matches given selector.
        Specified by:
        last in interface CapybaraPortingLayer
      • lastIfNotVisible

        public org.openqa.selenium.WebElement lastIfNotVisible​(org.openqa.selenium.By selector)
        Picks up the last visible element that matches given selector.
        Specified by:
        lastIfNotVisible in interface CapybaraPortingLayer
      • isStale

        protected static boolean isStale​(org.openqa.selenium.WebElement element)
        Returns true if the webElement is stale (that is accessing it would cause a StaleElementReferenceException to be thrown
        Parameters:
        element - the element to check.
        Returns:
        true iff the element is stale.
      • isHiddenOrStale

        protected static boolean isHiddenOrStale​(org.openqa.selenium.WebElement we)
      • runThenHandleDialog

        public void runThenHandleDialog​(Runnable runnable)
        Helper to execute something that shows a confirmation dialog with a "Yes" button or a classical browser confirm Executes the runnable, wait for "Yes" button of the modal dialog and presses the "Yes" button" In case the runnable opens a classical browse dialog this is accepted.
        Parameters:
        runnable -
      • handleAlert

        public void handleAlert​(Consumer<org.openqa.selenium.Alert> action)
      • runThenHandleAlert

        public void runThenHandleAlert​(Runnable runnable,
                                       Consumer<org.openqa.selenium.Alert> action)
      • runThenHandleAlert

        public void runThenHandleAlert​(Runnable runnable,
                                       Consumer<org.openqa.selenium.Alert> action,
                                       int timeoutSeconds)
      • confirmAlert

        public void confirmAlert​(int timeout)
        Description copied from interface: CapybaraPortingLayer
        Confirms an alert giving it some time to appear
        Specified by:
        confirmAlert in interface CapybaraPortingLayer
        Parameters:
        timeout - Maximum time to wait for the alert to appear, in seconds
      • runThenConfirmAlert

        public void runThenConfirmAlert​(Runnable runnable)
      • runThenConfirmAlert

        public void runThenConfirmAlert​(Runnable runnable,
                                        int timeout)
        Description copied from interface: CapybaraPortingLayer
        Do something that triggers an alert then giving it some time to appear
        Specified by:
        runThenConfirmAlert in interface CapybaraPortingLayer
        Parameters:
        runnable - Something that will trigger the alert
        timeout - Maximum time to wait for the alert to appear, in seconds
      • sleep

        public void sleep​(long ms)
        Thread.sleep that masks exception.
      • elasticSleep

        public void elasticSleep​(long ms)
      • newInstance

        protected <T> T newInstance​(Class<T> type,
                                    Object... args)
        Finds matching constructor and invoke it.

        This is often useful for binding PageArea by taking the concrete type as a parameter.

      • getPageSource

        public static String getPageSource​(org.openqa.selenium.WebDriver driver)
      • getPageContent

        public static String getPageContent​(org.openqa.selenium.WebDriver driver)
        Get visible text on the page.
      • resource

        public Resource resource​(String path)
        Obtains a resource in a wrapper.