Class WebDriverUtils

java.lang.Object
com.version1.webdriver.utils.WebDriverUtils

public class WebDriverUtils extends Object
WebDriver Utility class with helper methods for web element locators WebDriver explicit waits
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkPageTitle(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Check and matches the page title
    boolean
    checkPageTitleContains(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    checking that the title of a page contains a case-sensitive substring
    boolean
    checkPageUrlContains(String fraction, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    checking for fraction of the url that the page should be on
    boolean
    checkPageUrlMatches(String regex, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    checking for regular expression that the URL should match
    boolean
    checkPageUrlToBe(String url, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    checking for the URL of the current page to be a specific URL
    protected void
    clearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Clears the text field and then enters the text
    void
    clickWithinElementWithXYCoordinates(org.openqa.selenium.WebElement webElement, int x, int y, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Clicks on the element with x,y coordinates.
    protected org.openqa.selenium.WebElement
    element(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Finds an element on the web page
    boolean
    elementSelectionStateToBe(org.openqa.selenium.By by, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given element is selected.
    boolean
    elementSelectionStateToBe(org.openqa.selenium.WebElement element, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given element is selected.
    org.openqa.selenium.WebElement
    elementToBeClickable(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element to be clickable
    org.openqa.selenium.WebElement
    elementToBeClickable(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element to be clickable
    boolean
    elementToBeSelected(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given element is selected.
    boolean
    elementToBeSelected(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given element is selected.
    org.openqa.selenium.WebDriver
    frameToBeAvailableAndSwitchToIt(String frameLocator, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks whether the given frame is available to switch to If the frame is available it switches the given driver to the specified frame.
    org.openqa.selenium.WebDriver
    frameToBeAvailableAndSwitchToIt(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks whether the given frame is available to switch to If the frame is available it switches the given driver to the specified frame.
    getCurrentPageTitle(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Gets the current page title
    getCurrentUrl(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Gets the current URL
    getElementByQueryJSExecutor(String cssSelector, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Using JS Executor finds the element by document query selector.
    getElementByTagNameWithJSExecutor(String tagName, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Using JS Executor finds the element by tag name.
    boolean
    invisibilityOfElementLocated(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element to be invisible
    boolean
    invisibilityOfElementWithText(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element with text to be invisible
    boolean
    isElementPresent(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks the presence of element
    void
    navigateToPreviousPageUsingBrowserBackButton(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Navigates to the previous page using browser back button
    List<org.openqa.selenium.WebElement>
    presenceOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks the presence of all elements
    static void
    Sets the Clip board data
    boolean
    stalenessOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Wait until an element is no longer attached to the DOM
    boolean
    textToBePresentInElement(org.openqa.selenium.WebElement element, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks the text to be present in the Element
    boolean
    textToBePresentInElementLocated(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given text is present in the element that matches the given locator
    boolean
    textToBePresentInElementValue(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given text is present in the specified elements value attribute
    boolean
    textToBePresentInElementValue(org.openqa.selenium.WebElement element, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks if the given text is present in the specified elements value attribute
    org.openqa.selenium.WebElement
    visibilityOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks the visibility of elements
    List<org.openqa.selenium.WebElement>
    visibilityOfAllElements(List<org.openqa.selenium.WebElement> elements, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for all expected elements to be visible
    List<org.openqa.selenium.WebElement>
    visibilityOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for all expected elements to be visible
    protected org.openqa.selenium.support.ui.WebDriverWait
    Wait(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
     
    protected void
    waitClearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits before clearing the text field and then enters the text
    void
    waitForAlert(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Checks and waits for the presence of alert
    org.openqa.selenium.WebElement
    waitForExpectedElement(org.openqa.selenium.By by, long waitTimeInSeconds, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element to be visible till provided wait time in seconds
    protected org.openqa.selenium.WebElement
    waitForExpectedElement(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    Waits for the expected element to be visible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebDriverUtils

      public WebDriverUtils()
  • Method Details

    • Wait

      protected org.openqa.selenium.support.ui.WebDriverWait Wait(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
    • getCurrentUrl

      public String getCurrentUrl(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Gets the current URL
      Parameters:
      webDriver - used to execute the test cases
      Returns:
      URL, Returns the current URL
    • getCurrentPageTitle

      public String getCurrentPageTitle(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Gets the current page title
      Parameters:
      webDriver - used to execute the test cases
      Returns:
      page title, Returns the current page title
    • checkPageTitle

      public boolean checkPageTitle(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Check and matches the page title
      Parameters:
      title - , title to be matched with
      webDriver - used to execute the test cases
      Returns:
      boolean matching the title
    • checkPageTitleContains

      public boolean checkPageTitleContains(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      checking that the title of a page contains a case-sensitive substring
      Parameters:
      title - , title to be matched with
      webDriver - used to execute the test cases
      Returns:
      boolean matching the title of a page
    • checkPageUrlToBe

      public boolean checkPageUrlToBe(String url, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      checking for the URL of the current page to be a specific URL
      Parameters:
      url - , url to be matched with
      webDriver - used to execute the test cases
      Returns:
      boolean matching the url of a current page
    • checkPageUrlContains

      public boolean checkPageUrlContains(String fraction, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      checking for fraction of the url that the page should be on
      Parameters:
      fraction - , fraction of the url to be matched with
      webDriver - used to execute the test cases
      Returns:
      boolean matching the fraction of the url that the page should be on
    • checkPageUrlMatches

      public boolean checkPageUrlMatches(String regex, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      checking for regular expression that the URL should match
      Parameters:
      regex - , regular expression of the url to be matched with
      webDriver - used to execute the test cases
      Returns:
      boolean matching regular expression that the URL should match
    • waitForExpectedElement

      protected org.openqa.selenium.WebElement waitForExpectedElement(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for the expected element to be visible
      Parameters:
      by - which locates elements by the value of the attribute.
      webDriver - used to execute the test cases
      Returns:
      WebElement after the visibility of the Element
    • waitForExpectedElement

      public org.openqa.selenium.WebElement waitForExpectedElement(org.openqa.selenium.By by, long waitTimeInSeconds, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) throws TimeoutException
      Waits for the expected element to be visible till provided wait time in seconds
      Parameters:
      by - which locates elements by the value of the attribute
      waitTimeInSeconds - , time to wait for the visibility of the Element
      webDriver - used to execute the test cases
      Returns:
      WebElement after the visibility of the Element
      Throws:
      TimeoutException
    • textToBePresentInElement

      public boolean textToBePresentInElement(org.openqa.selenium.WebElement element, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks the text to be present in the Element
      Parameters:
      element - ,Element in which the presence of text needs to be verified
      text - to be verified
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the presence of the text
    • textToBePresentInElementLocated

      public boolean textToBePresentInElementLocated(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given text is present in the element that matches the given locator
      Parameters:
      by - which locates elements by the value of the attribute
      text - to be verified
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the presence of the text that matches the given locator
    • textToBePresentInElementValue

      public boolean textToBePresentInElementValue(org.openqa.selenium.WebElement element, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given text is present in the specified elements value attribute
      Parameters:
      element - ,Element in which the presence of text needs to be verified
      text - to be verified
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the presence of the text in the specified elements value attribute
    • textToBePresentInElementValue

      public boolean textToBePresentInElementValue(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given text is present in the specified elements value attribute
      Parameters:
      by - which locates elements by the value of the attribute
      text - to be verified
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the presence of the text in the specified elements value attribute
    • frameToBeAvailableAndSwitchToIt

      public org.openqa.selenium.WebDriver frameToBeAvailableAndSwitchToIt(String frameLocator, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks whether the given frame is available to switch to If the frame is available it switches the given driver to the specified frame.
      Parameters:
      frameLocator - ,Locator to the frame
      webDriver - used to execute the test cases
      Returns:
      WebDriver after the frame is available
    • frameToBeAvailableAndSwitchToIt

      public org.openqa.selenium.WebDriver frameToBeAvailableAndSwitchToIt(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks whether the given frame is available to switch to If the frame is available it switches the given driver to the specified frame.
      Parameters:
      by - which locates elements by the value of the attribute
      webDriver - used to execute the test cases
      Returns:
      WebDriver after the frame is available
    • invisibilityOfElementLocated

      public boolean invisibilityOfElementLocated(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for the expected element to be invisible
      Parameters:
      by - which locates elements by the value of the attribute.
      webDriver - used to execute the test cases
      Returns:
      boolean after the invisibility of the Element
    • invisibilityOfElementWithText

      public boolean invisibilityOfElementWithText(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for the expected element with text to be invisible
      Parameters:
      by - which locates elements by the value of the attribute.
      text - to be invisible.
      webDriver - used to execute the test cases
      Returns:
      boolean after the invisibility of the Element
    • elementToBeClickable

      public org.openqa.selenium.WebElement elementToBeClickable(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for the expected element to be clickable
      Parameters:
      by - which locates elements by the value of the attribute.
      webDriver - used to execute the test cases
      Returns:
      WebElement after the element is clickable
    • elementToBeClickable

      public org.openqa.selenium.WebElement elementToBeClickable(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for the expected element to be clickable
      Parameters:
      element - ,Element to be clickable
      webDriver - used to execute the test cases
      Returns:
      WebElement after the element is clickable
    • stalenessOf

      public boolean stalenessOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Wait until an element is no longer attached to the DOM
      Parameters:
      element - ,Element to be clickable
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the staleness of the element
    • elementToBeSelected

      public boolean elementToBeSelected(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given element is selected.
      Parameters:
      by - which locates elements by the value of the attribute.
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the selection of the element
    • elementToBeSelected

      public boolean elementToBeSelected(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given element is selected.
      Parameters:
      element - ,Element to be selected
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the selection of the element
    • elementSelectionStateToBe

      public boolean elementSelectionStateToBe(org.openqa.selenium.WebElement element, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given element is selected.
      Parameters:
      element - ,Element to be selected
      selected - , Boolean summarising the selected status
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the selection of the element
    • elementSelectionStateToBe

      public boolean elementSelectionStateToBe(org.openqa.selenium.By by, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks if the given element is selected.
      Parameters:
      by - which locates elements by the value of the attribute.
      selected - , Boolean summarising the selected status
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the selection of the element
    • waitForAlert

      public void waitForAlert(org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks and waits for the presence of alert
      Parameters:
      webDriver - used to execute the test cases
    • visibilityOfAllElementsLocatedBy

      public List<org.openqa.selenium.WebElement> visibilityOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for all expected elements to be visible
      Parameters:
      by - which locates elements by the value of the attribute.
      webDriver - used to execute the test cases
      Returns:
      List of WebElement after the visibility of the Elements
    • visibilityOfAllElements

      public List<org.openqa.selenium.WebElement> visibilityOfAllElements(List<org.openqa.selenium.WebElement> elements, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits for all expected elements to be visible
      Parameters:
      elements - , List of WebElement
      webDriver - used to execute the test cases
      Returns:
      List of WebElement after the visibility of the Elements
    • presenceOfAllElementsLocatedBy

      public List<org.openqa.selenium.WebElement> presenceOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks the presence of all elements
      Parameters:
      by - which locates elements by the value of the attribute
      webDriver - used to execute the test cases
      Returns:
      List of WebElement after the presence of the Elements
    • visibilityOf

      public org.openqa.selenium.WebElement visibilityOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks the visibility of elements
      Parameters:
      element - ,Element whose visibility is to be verified
      webDriver - used to execute the test cases
      Returns:
      WebElement after the visibility of the Element
    • isElementPresent

      public boolean isElementPresent(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Checks the presence of element
      Parameters:
      by - which locates elements by the value of the attribute
      webDriver - used to execute the test cases
      Returns:
      boolean summarising the presence of element
    • clickWithinElementWithXYCoordinates

      public void clickWithinElementWithXYCoordinates(org.openqa.selenium.WebElement webElement, int x, int y, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Clicks on the element with x,y coordinates.
      Parameters:
      webElement - ,Element which needs to be clicked
      x - , Coordinate x
      y - , Coordinate y
      webDriver - used to execute the test cases
    • getElementByTagNameWithJSExecutor

      public String getElementByTagNameWithJSExecutor(String tagName, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Using JS Executor finds the element by tag name.
      Parameters:
      tagName - ,Name of the tag
      webDriver - used to execute the test cases
      Returns:
      String representation of the object
    • getElementByQueryJSExecutor

      public String getElementByQueryJSExecutor(String cssSelector, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Using JS Executor finds the element by document query selector.
      Parameters:
      cssSelector - ,Name of Cascading Style Sheets
      webDriver - used to execute the test cases
      Returns:
      String representation of the object
    • element

      protected org.openqa.selenium.WebElement element(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Finds an element on the web page
      Parameters:
      by - which locates elements by the value of the attribute
      webDriver - used to execute the test cases
      Returns:
      WebElement after locating the element
    • clearEnterText

      protected void clearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Clears the text field and then enters the text
      Parameters:
      by - which locates elements by the value of the attribute
      inputText - , Text to be entered in the text field
      webDriver - used to execute the test cases
    • waitClearEnterText

      protected void waitClearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver)
      Waits before clearing the text field and then enters the text
      Parameters:
      by - which locates elements by the value of the attribute
      inputText - , Text to be entered in the text field
      webDriver - used to execute the test cases
    • setClipboardData

      public static void setClipboardData(String string)
      Sets the Clip board data
      Parameters:
      string - , String to be set in the clip board