Class WebBrowser

java.lang.Object
org.alfresco.utility.web.browser.WebBrowser

public class WebBrowser extends Object
A wrapper around an arbitrary WebDriver instance which supports registering of a WebDriverListener for logging purposes.
Author:
Paul.Brodner
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • properties

      protected TasProperties properties
    • driver

      protected final org.openqa.selenium.WebDriver driver
  • Constructor Details

    • WebBrowser

      public WebBrowser(org.openqa.selenium.WebDriver baseDriver, TasProperties properties)
    • WebBrowser

      public WebBrowser(org.openqa.selenium.WebDriver driver)
  • Method Details

    • authenticatedSession

      public WebBrowser authenticatedSession(org.apache.commons.httpclient.HttpState httpState)
      Inject auth cookie in current session so you don't need to login with LoginPage
    • cleanUpAuthenticatedSession

      public void cleanUpAuthenticatedSession()
      This is working in combination with authenticatedSession(HttpState)
    • mouseOver

      public void mouseOver(org.openqa.selenium.WebElement element)
      Recreating the action of hovering over a particular HTML element on a page.
      Parameters:
      element - WebElement target
    • mouseOver

      public void mouseOver(org.openqa.selenium.WebElement element, int xOffset, int yOffset)
      Recreating the action of hovering over with offset coordinates a particular HTML element on a page.
      Parameters:
      element - WebElement target
    • mouseOverViaJavascript

      public void mouseOverViaJavascript(org.openqa.selenium.WebElement webElement)
      Method to perform mouse over to a given web element, using JavaScript
      Parameters:
      webElement - web element which will take the mouse over event
    • refresh

      public void refresh()
      Acts as a refresh page action similar to F5 key.
    • waitUntilElementHasAttribute

      public void waitUntilElementHasAttribute(org.openqa.selenium.WebElement element, String attribute, String value)
      Wait until the element has attribute for the specified amount of time.
      Parameters:
      element -
    • waitUntilElementHasAttribute

      public void waitUntilElementHasAttribute(org.openqa.selenium.By locator, String attribute, String value)
    • waitUntilElementVisible

      public org.openqa.selenium.WebElement waitUntilElementVisible(org.openqa.selenium.By locator)
      Wait until the element is visible for the specified amount of time.
      Parameters:
      locator - By locator
    • waitUntilElementVisible

      public org.openqa.selenium.WebElement waitUntilElementVisible(org.openqa.selenium.By locator, long timeOutInSeconds)
      Wait until the element is visible for the specified amount of time.
      Parameters:
      locator - By locator
      timeOutInSeconds - timeout in seconds
    • waitUntilElementIsPresent

      public org.openqa.selenium.WebElement waitUntilElementIsPresent(org.openqa.selenium.By locator, long timeOutInSeconds)
      Wait until element is present on the DOM of a page.
      Parameters:
      locator - By locator
      timeOutInSeconds - seconds to wait
      Returns:
      WebElement
    • waitUntilElementIsPresent

      public org.openqa.selenium.WebElement waitUntilElementIsPresent(org.openqa.selenium.By locator)
      Wait until element is present on the DOM of a page.
      Parameters:
      locator - By locator
      Returns:
      WebElement
    • waitUntilChildElementIsPresent

      public org.openqa.selenium.WebElement waitUntilChildElementIsPresent(org.openqa.selenium.By parentLocator, org.openqa.selenium.By childLocator, long timeOutInSeconds)
      Wait for child WebElement as a part of parent element to present
      Parameters:
      parentLocator - By parent locator
      childLocator - By child locator
      timeOutInSeconds - seconds to wait
      Returns:
      WebElement
    • waitUntilChildElementIsPresent

      public org.openqa.selenium.WebElement waitUntilChildElementIsPresent(org.openqa.selenium.By parentLocator, org.openqa.selenium.By childLocator)
      Wait for child WebElement as a part of parent element to present
      Parameters:
      parentLocator - By parent locator
      childLocator - By child locator
      Returns:
      WebElement
    • waitUntilChildElementIsPresent

      public org.openqa.selenium.WebElement waitUntilChildElementIsPresent(org.openqa.selenium.WebElement parentLocator, org.openqa.selenium.By childLocator, long timeOutInSeconds)
      Wait for child WebElement as a part of parent element to present
      Parameters:
      parentLocator - WebElement parent locator
      childLocator - By child locator
      timeOutInSeconds - seconds to wait
      Returns:
      WebElement
    • waitUntilChildElementIsPresent

      public org.openqa.selenium.WebElement waitUntilChildElementIsPresent(org.openqa.selenium.WebElement parentLocator, org.openqa.selenium.By childLocator)
      Wait for child WebElement as a part of parent element to present
      Parameters:
      parentLocator - WebElement parent locator
      childLocator - By child locator
      Returns:
      WebElement
    • waitUntilElementVisible

      public org.openqa.selenium.WebElement waitUntilElementVisible(org.openqa.selenium.WebElement element)
      Wait until the element is visible for the specified amount of time.
      Parameters:
      element - WebElement web element
    • waitUntilElementVisible

      public org.openqa.selenium.WebElement waitUntilElementVisible(org.openqa.selenium.WebElement element, long timeOutInSeconds)
      Wait until the element is visible for the specified amount of time.
      Parameters:
      element - WebElement web element
      timeOutInSeconds - timeout in seconds
    • waitUntilElementsVisible

      public List<org.openqa.selenium.WebElement> waitUntilElementsVisible(org.openqa.selenium.By locator)
      Helper method to find and return a slow loading collection of WebElement.
      Parameters:
      locator - By search criteria
      Returns:
      Collection of WebElement HTML elements
    • waitUntilElementsVisible

      public List<org.openqa.selenium.WebElement> waitUntilElementsVisible(List<org.openqa.selenium.WebElement> elements)
      Helper method to find and return a slow loading collection of WebElement.
      Parameters:
      elements - WebElement search criteria
      Returns:
      Collection of WebElement HTML elements
    • waitUntilElementIsDisplayedWithRetry

      public void waitUntilElementIsDisplayedWithRetry(org.openqa.selenium.By locator)
      Wait the element is displayed by refreshing the page
      Parameters:
      locator - By query
    • waitUntilElementIsDisplayedWithRetry

      public void waitUntilElementIsDisplayedWithRetry(org.openqa.selenium.By locator, int secondsToWait)
      Wait the element is displayed by refreshing the page
      Parameters:
      locator - By query
      secondsToWait -
    • waitUntilElementIsDisplayedWithRetry

      public void waitUntilElementIsDisplayedWithRetry(org.openqa.selenium.By locator, int secondsToWait, int retryTimes)
      Wait the element is displayed by refreshing the page
      Parameters:
      locator - By query
      secondsToWait -
      retryTimes -
    • waitWithRetryAndReturnWebElement

      public org.openqa.selenium.WebElement waitWithRetryAndReturnWebElement(org.openqa.selenium.By locator, int secondsToWait, int retryTimes)
    • waitUntilElementIsDisplayedWithRetry

      public void waitUntilElementIsDisplayedWithRetry(org.openqa.selenium.WebElement webElement, int secondsToWait)
      Wait the element is displayed by refreshing the page
      Parameters:
      webElement - WebElement query
      secondsToWait -
    • waitUntilElementDisappearsWithRetry

      public void waitUntilElementDisappearsWithRetry(org.openqa.selenium.By locator, int secondsToWait)
      Wait the element to disappear by refreshing the page
      Parameters:
      locator - By query
      secondsToWait -
    • waitUntilWebElementIsDisplayedWithRetry

      public void waitUntilWebElementIsDisplayedWithRetry(org.openqa.selenium.WebElement webElement)
      Wait until one element is displayed by refreshing the page
      Parameters:
      webElement -
    • waitUntilWebElementIsDisplayedWithRetry

      public void waitUntilWebElementIsDisplayedWithRetry(org.openqa.selenium.WebElement webElement, int secondsToWait)
      Wait until one element is displayed by refreshing the page
      Parameters:
      webElement -
      secondsToWait -
    • waitUntilElementClickable

      public org.openqa.selenium.WebElement waitUntilElementClickable(org.openqa.selenium.WebElement element)
      Wait until the Clickable of given Element for given seconds.
      Parameters:
      element - WebElement
    • waitUntilElementClickable

      public org.openqa.selenium.WebElement waitUntilElementClickable(org.openqa.selenium.By locator)
    • waitUntilElementClickable

      public org.openqa.selenium.WebElement waitUntilElementClickable(org.openqa.selenium.By locator, long timeOutInSeconds)
      Wait until the Clickable of given Element for given seconds.
      Parameters:
      locator - CSS Locator
      timeOutInSeconds - Timeout In Seconds
    • waitUntilElementClickable

      public org.openqa.selenium.WebElement waitUntilElementClickable(org.openqa.selenium.WebElement element, long timeOutInSeconds)
      Wait until the Clickable of given Element for given seconds.
      Parameters:
      element - WebElement
      timeOutInSeconds - Timeout In Seconds
    • waitUntilElementContainsText

      public void waitUntilElementContainsText(org.openqa.selenium.WebElement element, String text)
      Wait until the given text is present in the given Element
      Parameters:
      element - WebElement
    • waitUntilElementContainsText

      public void waitUntilElementContainsText(org.openqa.selenium.By locator, String text)
      Wait until the given text is present in the given Locator
      Parameters:
      locator - Locator
    • waitUrlContains

      public void waitUrlContains(String URLfraction, long timeOutInSeconds)
      Wait until url contains the given URL fraction.
      Parameters:
      URLfraction -
      timeOutInSeconds -
    • waitUntilElementDeletedFromDom

      public void waitUntilElementDeletedFromDom(org.openqa.selenium.By locator)
      Wait Until element successfully deleting from DOM.
      Parameters:
      locator - By locator
    • waitUntilElementDeletedFromDom

      public void waitUntilElementDeletedFromDom(org.openqa.selenium.By locator, long timeOutInSeconds)
      Wait Until element successfully deleting from DOM.
      Parameters:
      locator - By locator
      timeOutInSeconds - time to wait
    • waitUntilElementDisappears

      public void waitUntilElementDisappears(org.openqa.selenium.By locator)
      Wait until the invisibility of given Element for given seconds.
      Parameters:
      locator - CSS Locator
    • waitUntilElementDisappears

      public void waitUntilElementDisappears(org.openqa.selenium.By locator, long timeOutInSeconds)
      Wait until the invisibility of given Element for given seconds.
      Parameters:
      locator - By Locator
      timeOutInSeconds - timeout In Seconds
    • waitUntilElementDisappears

      public void waitUntilElementDisappears(org.openqa.selenium.WebElement locator, long timeOutInSeconds)
      Wait until the invisibility of given Element for given seconds.
      Parameters:
      locator - By Locator
      timeOutInSeconds - timeout In Seconds
    • waitUntilElementDisappears

      public void waitUntilElementDisappears(org.openqa.selenium.WebElement locator)
      Wait until the invisibility of given Element for given seconds.
      Parameters:
      locator - CSS Locator
    • isElementDisplayed

      public boolean isElementDisplayed(org.openqa.selenium.By locator)
      Returns true if the element is displayed else false.
      Parameters:
      locator - By query
      Returns:
      boolean true if displayed
    • isElementDisplayed

      public boolean isElementDisplayed(org.openqa.selenium.WebElement element)
      Returns true if the element is displayed else false.
      Parameters:
      element - By query
      Returns:
      boolean true if displayed
    • isElementDisplayed

      public boolean isElementDisplayed(org.openqa.selenium.WebElement element, org.openqa.selenium.By locator)
      Returns true if the element is displayed else false.
      Parameters:
      locator - WebElement query By query
      Returns:
      boolean true if displayed
    • getPreviousUrl

      public String getPreviousUrl()
      Gets the URL of the previously visited page. The previous url is only displayed once interacted with the page. If user uses drone.navigetTo it will treat it as an entry page and will not have a previous page url.
      Returns:
      String previous page URL
    • switchToFrame

      public void switchToFrame(String frameId)
      Method to switch on to frames of content object.
      Parameters:
      frameId - String identifier
    • switchToDefaultContent

      public void switchToDefaultContent()
      Method to switch back from i-frame to default content.
    • switchWindow

      public void switchWindow()
      Switches to the newly created window.
    • switchWindow

      public void switchWindow(int windowIndex)
      Waits and switches to window based on index
    • switchWindow

      public void switchWindow(String winHandler)
      Switches to window with specified url.
    • closeWindowAndSwitchBack

      public void closeWindowAndSwitchBack()
      Closes the newly created win and swithes back to main
    • closeWindowAndSwitchBackParametrized

      public void closeWindowAndSwitchBackParametrized(String windowToSwitchTo, String windowToClose)
      Closes the window and returns to selected window
    • closeWindowAcceptingModalDialog

      public void closeWindowAcceptingModalDialog()
      Closes the window opened leaving the browser session opened
    • switchToWindow

      public void switchToWindow(String windowHandle)
      This method transfers the control to the specific window as per the given window handle.
      Parameters:
      windowHandle - identifier
    • getCookie

      public org.openqa.selenium.Cookie getCookie(String name)
      Get a cookie that matches the name.
      Parameters:
      name - String cookie identifier
      Returns:
      Cookie object
    • deleteCookies

      public void deleteCookies()
      Function to delete the cookies in the browser
    • deleteCookie

      public void deleteCookie(org.openqa.selenium.Cookie cookie)
      Delete cookie based on given cookie.
      Parameters:
      cookie - Cookie object to be deleted.
    • maximize

      public void maximize()
      Maximizes the current window if it is not already maximized
    • dragAndDrop

      public void dragAndDrop(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target)
      Drag the source element and drop into target element.
      Parameters:
      source - Source WebElement
      target - Target WebElement
    • dragAndDrop

      public void dragAndDrop(org.openqa.selenium.WebElement source, int x, int y)
      Drag web element by x,y coordinates
      Parameters:
      source - html WebElement
      x - coordinate
      y - coordinate
    • doubleClickOnElement

      public void doubleClickOnElement(org.openqa.selenium.WebElement element)
      Double click on an element
      Parameters:
      element - WebElement
    • rightClickOnElement

      public void rightClickOnElement(org.openqa.selenium.WebElement element)
      Right click on an element
      Parameters:
      element - WebElement
    • findFirstDisplayedElement

      public org.openqa.selenium.WebElement findFirstDisplayedElement(org.openqa.selenium.By locator)
      This function will return 1st visible element found with the specified selector
      Parameters:
      locator - By selector type
      Returns:
      WebElement element to interact
    • findFirstElementWithValue

      public org.openqa.selenium.WebElement findFirstElementWithValue(org.openqa.selenium.By locator, String value)
      This function will return 1st element found with a specified value
      Parameters:
      locator - By identifier
      Returns:
      List of WebElement
    • findFirstElementWithValue

      public org.openqa.selenium.WebElement findFirstElementWithValue(List<org.openqa.selenium.WebElement> list, String value)
      This function will return 1st element found which contains a specified value
      Parameters:
      list - List<org.openqa.selenium.WebElement> identifier
      Returns:
      List of WebElement
    • findFirstElementWithExactValue

      public org.openqa.selenium.WebElement findFirstElementWithExactValue(List<org.openqa.selenium.WebElement> list, String value)
      This function will return 1st element found with the exact specified value
      Parameters:
      list -
      value -
      Returns:
    • findDisplayedElementsFromLocator

      public List<org.openqa.selenium.WebElement> findDisplayedElementsFromLocator(org.openqa.selenium.By selector)
      This function will return list of visible elements found with the specified selector
      Parameters:
      selector - By identifier
      Returns:
      List of WebElement
    • selectOptionFromFilterOptionsList

      public void selectOptionFromFilterOptionsList(String option, List<org.openqa.selenium.WebElement> filterOptionsList)
      This function selects specified filter option from filter options list
      Parameters:
      option - Option to be selected
      filterOptionsList - The filter Option List
    • isOptionSelectedForFilter

      public boolean isOptionSelectedForFilter(String option, org.openqa.selenium.WebElement filterElement)
    • scrollToElement

      public void scrollToElement(org.openqa.selenium.WebElement element)
      Scroll to WebElement
      Parameters:
      element - WebElement
    • scrollIntoView

      public void scrollIntoView(org.openqa.selenium.WebElement element)
      Scroll to WebElement
      Parameters:
      element - WebElement
    • waitInSeconds

      public void waitInSeconds(int seconds)
      Method to wait for given seconds.
      Parameters:
      seconds - time in seconds
    • executeJavaScript

      public void executeJavaScript(String command)
      Execute Javascript command
      Parameters:
      command -
    • executeJavaScript

      public void executeJavaScript(String command, org.openqa.selenium.WebElement element)
      Execute Javascript command with WebElement
      Parameters:
      command -
      element - WebElement
    • clickJS

      public void clickJS(org.openqa.selenium.WebElement elementToClick)
      Click WebElement with JavaScript command
      Parameters:
      elementToClick -
    • isAlertPresent

      public boolean isAlertPresent()
    • handleModalDialogAcceptingAlert

      public void handleModalDialogAcceptingAlert()
    • handleModalDialogDismissingAlert

      public void handleModalDialogDismissingAlert()
    • focusOnWebElement

      public void focusOnWebElement(org.openqa.selenium.WebElement webElement)
    • waitUntilElementIsVisibleWithRetry

      public void waitUntilElementIsVisibleWithRetry(org.openqa.selenium.By locator, int retryCount)
      Wait until element is visible with retry
      Parameters:
      locator -
      retryCount -
    • waitUntilElementDoesNotContainText

      public void waitUntilElementDoesNotContainText(org.openqa.selenium.WebElement element, String text)
      Wait until the given text is not present in the given Element
      Parameters:
      element - WebElement
    • getTextFromLocatorList

      public List<String> getTextFromLocatorList(org.openqa.selenium.By elementsList)
    • getTextFromElementList

      public List<String> getTextFromElementList(List<org.openqa.selenium.WebElement> elementsList)
    • getDriver

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

      public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
    • findElements

      public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
    • switchTo

      public org.openqa.selenium.WebDriver.TargetLocator switchTo()
    • getCurrentUrl

      public String getCurrentUrl()
    • get

      public void get(String url)
    • quit

      public void quit()