Class DriverHelper

  • Direct Known Subclasses:
    AbstractUIObject

    public class DriverHelper
    extends java.lang.Object
    DriverHelper - WebDriver wrapper for logging and reporting features. Also it contains some complex operations with UI.
    Author:
    Alex Khursevich
    • Field Detail

      • EXPLICIT_TIMEOUT

        protected static final long EXPLICIT_TIMEOUT
      • SHORT_TIMEOUT

        protected static final long SHORT_TIMEOUT
      • RETRY_TIME

        protected static final long RETRY_TIME
      • timer

        protected long timer
      • driver

        protected org.openqa.selenium.WebDriver driver
      • pageURL

        protected java.lang.String pageURL
      • cryptoTool

        protected com.zebrunner.carina.crypto.CryptoTool cryptoTool
      • CRYPTO_PATTERN

        protected static java.lang.String CRYPTO_PATTERN
    • Constructor Detail

      • DriverHelper

        public DriverHelper()
      • DriverHelper

        public DriverHelper​(org.openqa.selenium.WebDriver driver)
    • Method Detail

      • open

        public void open()
        Opens page according to specified in constructor URL.
      • openURL

        public void openURL​(java.lang.String url)
        Open URL.
        Parameters:
        url - to open.
      • openURL

        public void openURL​(java.lang.String url,
                            long timeout)
        Open URL.
        Parameters:
        url - to open.
        timeout - long
      • setPageURL

        protected void setPageURL​(java.lang.String relURL)
      • setPageAbsoluteURL

        protected void setPageAbsoluteURL​(java.lang.String url)
      • getPageURL

        public java.lang.String getPageURL()
      • allElementsPresent

        public boolean allElementsPresent​(ExtendedWebElement... elements)
        Method which quickly looks for all element and check that they present during EXPLICIT_TIMEOUT
        Parameters:
        elements - ExtendedWebElement...
        Returns:
        boolean return true only if all elements present.
      • allElementsPresent

        public boolean allElementsPresent​(long timeout,
                                          ExtendedWebElement... elements)
        Method which quickly looks for all element and check that they present during timeout sec
        Parameters:
        timeout - long
        elements - ExtendedWebElement...
        Returns:
        boolean return true only if all elements present.
      • allElementListsAreNotEmpty

        public boolean allElementListsAreNotEmpty​(java.util.List<ExtendedWebElement>... elements)
        Method which quickly looks for all element lists and check that they contain at least one element during SHORT_TIMEOUT
        Parameters:
        elements - List<ExtendedWebElement>...
        Returns:
        boolean
      • allElementListsAreNotEmpty

        public boolean allElementListsAreNotEmpty​(long timeout,
                                                  java.util.List<ExtendedWebElement>... elements)
        Method which quickly looks for all element lists and check that they contain at least one element during timeout
        Parameters:
        timeout - long
        elements - List<ExtendedWebElement>...
        Returns:
        boolean return true only if All Element lists contain at least one element
      • isAnyElementPresent

        public boolean isAnyElementPresent​(ExtendedWebElement... elements)
        Method which quickly looks for any element presence during SHORT_TIMEOUT
        Parameters:
        elements - ExtendedWebElement...
        Returns:
        true if any of elements was found.
      • isAnyElementPresent

        public boolean isAnyElementPresent​(long timeout,
                                           ExtendedWebElement... elements)
        Method which quickly looks for any element presence during timeout sec
        Parameters:
        timeout - long
        elements - ExtendedWebElement...
        Returns:
        true if any of elements was found.
      • returnAnyPresentElement

        public ExtendedWebElement returnAnyPresentElement​(ExtendedWebElement... elements)
        return Any Present Element from the list which present during SHORT_TIMEOUT
        Parameters:
        elements - ExtendedWebElement...
        Returns:
        ExtendedWebElement
      • returnAnyPresentElement

        public ExtendedWebElement returnAnyPresentElement​(long timeout,
                                                          ExtendedWebElement... elements)
        return Any Present Element from the list which present during timeout sec
        Parameters:
        timeout - long
        elements - ExtendedWebElement...
        Returns:
        ExtendedWebElement
      • isElementWithTextPresent

        public boolean isElementWithTextPresent​(ExtendedWebElement extWebElement,
                                                java.lang.String text)
        Check that element with text present.
        Parameters:
        extWebElement - to check if element with text is present
        text - of element to check.
        Returns:
        element with text existence status.
      • isElementWithTextPresent

        public boolean isElementWithTextPresent​(ExtendedWebElement extWebElement,
                                                java.lang.String text,
                                                long timeout)
        Check that element with text present.
        Parameters:
        extWebElement - to check if element with text is present
        text - of element to check.
        timeout - Long
        Returns:
        element with text existence status.
      • isElementNotPresent

        public boolean isElementNotPresent​(ExtendedWebElement extWebElement)
        Check that element not present on page.
        Parameters:
        extWebElement - to check if element is not present
        Returns:
        element non-existence status.
      • isElementNotPresent

        public boolean isElementNotPresent​(ExtendedWebElement extWebElement,
                                           long timeout)
        Check that element not present on page.
        Parameters:
        extWebElement - to check if element is not present
        timeout - to wait
        Returns:
        element non-existence status.
      • isElementNotPresent

        public boolean isElementNotPresent​(java.lang.String controlInfo,
                                           org.openqa.selenium.WebElement element)
        Check that element not present on page.
        Parameters:
        element - to check if element is not present
        controlInfo - String
        Returns:
        element non-existence status.
      • clickAny

        public void clickAny​(ExtendedWebElement... elements)
        Clicks on element.
        Parameters:
        elements - ExtendedWebElements to click
      • clickAny

        public void clickAny​(long timeout,
                             ExtendedWebElement... elements)
        Clicks on element.
        Parameters:
        elements - ExtendedWebElements to click
        timeout - to wait
      • getPageSource

        public java.lang.String getPageSource()
      • addCookie

        public void addCookie​(org.openqa.selenium.Cookie cookie)
      • getCurrentUrl

        public java.lang.String getCurrentUrl()
        Get a string representing the current URL that the browser is looking at.
        Returns:
        url.
      • getCurrentUrl

        public java.lang.String getCurrentUrl​(long timeout)
        Get a string representing the current URL that the browser is looking at.
        Parameters:
        timeout - long
        Returns:
        validation result.
      • isUrlAsExpected

        public boolean isUrlAsExpected​(java.lang.String expectedURL)
        Checks that current URL is as expected.
        Parameters:
        expectedURL - Expected Url
        Returns:
        validation result.
      • isUrlAsExpected

        public boolean isUrlAsExpected​(java.lang.String expectedURL,
                                       long timeout)
        Checks that current URL is as expected.
        Parameters:
        expectedURL - Expected Url
        timeout - long
        Returns:
        validation result.
      • getClipboardText

        public java.lang.String getClipboardText()
        Returns:
        String saved in clipboard
      • setClipboardText

        public boolean setClipboardText​(java.lang.String text)
        Set text to clipboard
        Parameters:
        text - text
        Returns:
        true if successfull, false otherwise
      • pause

        public void pause​(long timeout)
        Pause for specified timeout.
        Parameters:
        timeout - in seconds.
      • pause

        public void pause​(java.lang.Double timeout)
      • getTitle

        public java.lang.String getTitle()
        Return page title.
        Returns:
        title String.
      • getTitle

        public java.lang.String getTitle​(long timeout)
        Return page title.
        Parameters:
        timeout - long
        Returns:
        title String.
      • isTitleAsExpected

        public boolean isTitleAsExpected​(java.lang.String expectedTitle)
        Checks that page title is as expected.
        Parameters:
        expectedTitle - Expected title
        Returns:
        validation result.
      • isTitleAsExpectedPattern

        public boolean isTitleAsExpectedPattern​(java.lang.String expectedPattern)
        Checks that page suites to expected pattern.
        Parameters:
        expectedPattern - Expected Pattern
        Returns:
        validation result.
      • navigateBack

        public void navigateBack()
        Go back in browser.
      • refresh

        public void refresh()
        Refresh browser.
      • refresh

        public void refresh​(long timeout)
        Refresh browser.
        Parameters:
        timeout - long
      • pressTab

        public void pressTab()
      • dragAndDrop

        public void dragAndDrop​(ExtendedWebElement from,
                                ExtendedWebElement to)
        Drags and drops element to specified place.
        Parameters:
        from - - element to drag.
        to - - element to drop to.
      • dragAndDropHtml5

        public void dragAndDropHtml5​(ExtendedWebElement from,
                                     ExtendedWebElement to)
        Drags and drops element to specified place. Elements Need To have an id.
        Parameters:
        from - - the element to drag.
        to - - the element to drop to.
      • slide

        public void slide​(ExtendedWebElement slider,
                          int moveX,
                          int moveY)
        Performs slider move for specified offset.
        Parameters:
        slider - slider
        moveX - move x
        moveY - move y
      • acceptAlert

        public void acceptAlert()
        Accepts alert modal.
      • cancelAlert

        public void cancelAlert()
        Cancels alert modal.
      • isAlertPresent

        public boolean isAlertPresent()
        Checks that alert modal is shown.
        Returns:
        whether the alert modal present.
      • isPageOpened

        public boolean isPageOpened​(AbstractPage page)
      • isPageOpened

        public boolean isPageOpened​(AbstractPage page,
                                    long timeout)
      • trigger

        public java.lang.Object trigger​(java.lang.String script,
                                        org.openqa.selenium.WebElement element)
        Executes a script on an element Really should only be used when the web driver is sucking at exposing functionality natively
        Parameters:
        script - The script to execute
        element - The target of the script, referenced as arguments[0]
        Returns:
        Object
      • trigger

        public java.lang.Object trigger​(java.lang.String script)
        Executes a script Really should only be used when the web driver is sucking at exposing functionality natively
        Parameters:
        script - The script to execute
        Returns:
        Object
      • openTab

        public void openTab​(java.lang.String url)
        Opens a new tab for the given URL
        Parameters:
        url - The URL to
        Throws:
        java.lang.RuntimeException - If unable to open tab
      • switchWindow

        public void switchWindow()
                          throws org.openqa.selenium.NoSuchWindowException
        Throws:
        org.openqa.selenium.NoSuchWindowException
      • assertElementPresent

        public void assertElementPresent​(ExtendedWebElement extWebElement)
      • assertElementPresent

        public void assertElementPresent​(ExtendedWebElement extWebElement,
                                         long timeout)
      • assertElementWithTextPresent

        public void assertElementWithTextPresent​(ExtendedWebElement extWebElement,
                                                 java.lang.String text)
      • assertElementWithTextPresent

        public void assertElementWithTextPresent​(ExtendedWebElement extWebElement,
                                                 java.lang.String text,
                                                 long timeout)
      • findExtendedWebElement

        public ExtendedWebElement findExtendedWebElement​(org.openqa.selenium.By by)
        Find element on the page
        Element search is limited by the Configuration.Parameter.EXPLICIT_TIMEOUT
        Parameters:
        by - see By
        Returns:
        ExtendedWebElement if exists, null otherwise
      • findExtendedWebElement

        public ExtendedWebElement findExtendedWebElement​(org.openqa.selenium.By by,
                                                         long timeout)
        Find element on the page
        Parameters:
        by - see By
        timeout - time to wait, in seconds
        Returns:
        ExtendedWebElement if exists, null otherwise
      • findExtendedWebElement

        public ExtendedWebElement findExtendedWebElement​(org.openqa.selenium.By by,
                                                         java.lang.String name)
        Find element on the page
        Element search is limited by the Configuration.Parameter.EXPLICIT_TIMEOUT
        Parameters:
        by - see By
        name - the name that will be given to the found element
        Returns:
        ExtendedWebElement if exists, null otherwise
      • findExtendedWebElement

        public ExtendedWebElement findExtendedWebElement​(org.openqa.selenium.By by,
                                                         java.lang.String name,
                                                         long timeout)
        Find element on the page
        Parameters:
        by - see By
        name - the name that will be given to the found element
        timeout - time to wait, in seconds
        Returns:
        ExtendedWebElement if exists, null otherwise
      • findExtendedWebElements

        public java.util.List<ExtendedWebElement> findExtendedWebElements​(org.openqa.selenium.By by)
        Find elements on the page
        Elements search is limited by the Configuration.Parameter.EXPLICIT_TIMEOUT
        Parameters:
        by - see By
        Returns:
        list of ExtendedWebElements, empty list otherwise
      • findExtendedWebElements

        public java.util.List<ExtendedWebElement> findExtendedWebElements​(org.openqa.selenium.By by,
                                                                          long timeout)
        Find elements on the page
        Parameters:
        by - see By
        timeout - time to wait, in seconds
        Returns:
        list of ExtendedWebElements if found, empty list otherwise
      • setDriver

        protected void setDriver​(org.openqa.selenium.WebDriver driver)
      • getDriver

        public org.openqa.selenium.WebDriver getDriver()
      • waitUntil

        public boolean waitUntil​(org.openqa.selenium.support.ui.ExpectedCondition<?> condition,
                                 long timeout)
        Wait until any condition happens.
        Parameters:
        condition - - ExpectedCondition.
        timeout - - timeout.
        Returns:
        true if condition happen.
      • performIgnoreException

        public <T> T performIgnoreException​(java.util.function.Supplier<T> supplier)