Package com.version1.webdriver.utils
Class WebDriverUtils
java.lang.Object
com.version1.webdriver.utils.WebDriverUtils
WebDriver Utility class with helper methods for web element locators
WebDriver explicit waits
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckPageTitle(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Check and matches the page titlebooleancheckPageTitleContains(String title, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) checking that the title of a page contains a case-sensitive substringbooleancheckPageUrlContains(String fraction, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) checking for fraction of the url that the page should be onbooleancheckPageUrlMatches(String regex, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) checking for regular expression that the URL should matchbooleancheckPageUrlToBe(String url, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) checking for the URL of the current page to be a specific URLprotected voidclearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Clears the text field and then enters the textvoidclickWithinElementWithXYCoordinates(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.WebElementelement(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Finds an element on the web pagebooleanelementSelectionStateToBe(org.openqa.selenium.By by, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks if the given element is selected.booleanelementSelectionStateToBe(org.openqa.selenium.WebElement element, boolean selected, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks if the given element is selected.org.openqa.selenium.WebElementelementToBeClickable(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for the expected element to be clickableorg.openqa.selenium.WebElementelementToBeClickable(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for the expected element to be clickablebooleanelementToBeSelected(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks if the given element is selected.booleanelementToBeSelected(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks if the given element is selected.org.openqa.selenium.WebDriverframeToBeAvailableAndSwitchToIt(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.WebDriverframeToBeAvailableAndSwitchToIt(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 titlegetCurrentUrl(org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Gets the current URLgetElementByQueryJSExecutor(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.booleaninvisibilityOfElementLocated(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for the expected element to be invisiblebooleaninvisibilityOfElementWithText(org.openqa.selenium.By by, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for the expected element with text to be invisiblebooleanisElementPresent(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks the presence of elementvoidnavigateToPreviousPageUsingBrowserBackButton(org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Navigates to the previous page using browser back buttonList<org.openqa.selenium.WebElement>presenceOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks the presence of all elementsstatic voidsetClipboardData(String string) Sets the Clip board databooleanstalenessOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Wait until an element is no longer attached to the DOMbooleantextToBePresentInElement(org.openqa.selenium.WebElement element, String text, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks the text to be present in the ElementbooleantextToBePresentInElementLocated(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 locatorbooleantextToBePresentInElementValue(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 attributebooleantextToBePresentInElementValue(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 attributeorg.openqa.selenium.WebElementvisibilityOf(org.openqa.selenium.WebElement element, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks the visibility of elementsList<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 visibleList<org.openqa.selenium.WebElement>visibilityOfAllElementsLocatedBy(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for all expected elements to be visibleprotected org.openqa.selenium.support.ui.WebDriverWaitWait(org.openqa.selenium.support.events.EventFiringWebDriver webDriver) protected voidwaitClearEnterText(org.openqa.selenium.By by, String inputText, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits before clearing the text field and then enters the textvoidwaitForAlert(org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Checks and waits for the presence of alertorg.openqa.selenium.WebElementwaitForExpectedElement(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 secondsprotected org.openqa.selenium.WebElementwaitForExpectedElement(org.openqa.selenium.By by, org.openqa.selenium.support.events.EventFiringWebDriver webDriver) Waits for the expected element to be visible
-
Constructor Details
-
WebDriverUtils
public WebDriverUtils()
-
-
Method Details
-
Wait
protected org.openqa.selenium.support.ui.WebDriverWait Wait(org.openqa.selenium.support.events.EventFiringWebDriver webDriver) -
getCurrentUrl
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 withwebDriver- 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 withwebDriver- 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 withwebDriver- 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 withwebDriver- 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 withwebDriver- 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 attributewaitTimeInSeconds- , time to wait for the visibility of the ElementwebDriver- 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 verifiedtext- to be verifiedwebDriver- 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 attributetext- to be verifiedwebDriver- 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 verifiedtext- to be verifiedwebDriver- 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 attributetext- to be verifiedwebDriver- 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 framewebDriver- 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 attributewebDriver- 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 clickablewebDriver- 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 clickablewebDriver- 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 selectedwebDriver- 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 selectedselected- , Boolean summarising the selected statuswebDriver- 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 statuswebDriver- 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 WebElementwebDriver- 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 attributewebDriver- 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 verifiedwebDriver- 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 attributewebDriver- 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 clickedx- , Coordinate xy- , Coordinate ywebDriver- 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 tagwebDriver- 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 SheetswebDriver- 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 attributewebDriver- 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 attributeinputText- , Text to be entered in the text fieldwebDriver- 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 attributeinputText- , Text to be entered in the text fieldwebDriver- used to execute the test cases
-
setClipboardData
Sets the Clip board data- Parameters:
string- , String to be set in the clip board
-