Skip to content

Latest commit

 

History

History
470 lines (308 loc) · 25.2 KB

driver.md

File metadata and controls

470 lines (308 loc) · 25.2 KB

Driver

this.driver class methods

navigateTo(url, checkUrl)

Navigate to a particular URL, with optional verification of navigated URL

Param Type Default Description
url string URL to navigate
checkUrl boolean true Optional verification to check if navigation was successful within timeout

refreshCurrentPage()

Refresh current page

close()

Quit or close the current driver session

waitForElements(strategy, locator) ⇒ *

Wait for specified element(s) to appear and returns them as an array

Returns: * - Returns the array of WebElementPromises if found;

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

waitForElement(strategy, locator) ⇒ WebElementPromise

Wait for A SINGLE specified element to appear and returns them as an array

Returns: WebElementPromise - Returns a WebElementPromise if found;

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

click(strategy, locator, caller)

Click on an element in the webpage

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
caller function Optional parameter to indicate the function name that called this method

type(strategy, locator, value)

Type value into the specified input field element in the webpage

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of input field element to search, corresponding to locator strategy
value string Value to be entered in the input field

fillInDate(baseId)

Custom function to enter date, month and year value in a 3-split dd-mm-YYYY date field

Param Type Description
baseId string Id value of the element based on 'id' locator strategy

clear(strategy, locator)

Clear value present in an input field element in the webpage

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of input field element to search, corresponding to locator strategy

getText(strategy, locator, waitForText)

Waits for elements as specified, and returns the text attribute of the first element

Param Type Default Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
waitForText boolean false set to true, if function should wait until element text is not empty

getTexts(strategy, locator)

Waits for elements as specified, and returns the text attribute of the all the elements

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

checkTextsAre(strategy, locator, stringArr)

Custom function to verify multiple text values in multiple elements discovered using a common locator strategy

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
stringArr Array Array of text values to be verified in the discovered elements

waitUntilTextIs(strategy, locator, value, timeout)

Waits until the element's innertext value is equal to expected text, within timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
value string expected text value for verification
timeout number optional timeout that overrides the default webdriver timeout

waitUntilInputIs(strategy, locator, value)

Waits until the element's input value is equal to expected text, within timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
value string expected input text value for verification

waitUntilNumberOfElementsFound(strategy, locator, count)

Waits until a certain number of elements for the specified locator strategy is found, until timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
count number expected number of elements

waitUntilTextContains(strategy, locator, value, timeout)

Waits until the element's innertext value contains the expected text, within timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
value string expected text value
timeout number optional timeout, overriding the global driver timeout

findElements(strategy, locator) ⇒ *

Finds all elements with provided locator strategy and returns them as an WebElement array

Returns: * - Returns the array of WebElementPromises if found;

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

scrollToElement(element) ⇒ Promise.<void>

Function to scroll to the position of a specific element on the browser

Returns: Promise.<void> - An empty promise

Param Type Description
element WebElement Element to search on the target browser

isElementVisible(element) ⇒ boolean

Function to validate whether an element is visible on the browser viewport (works on desktop/ios/android)

Returns: boolean - Return true if found; or else, false

Param Type Description
element WebElement Element to search on the target browser

selectRadioButtonById(id)

Select radio button identified by id locator strategy

Param Type Description
id string Id value of the element based on 'id' locator strategy

selectCheckboxById(id)

Select checkbox element identified by id locator strategy

Param Type Description
id string Id value of the element based on 'id' locator strategy

waitForCheckboxToBeSelected(id)

Waits for checkbox element to become visible and selectable, identified by id locator strategy

Param Type Description
id string Id value of the element based on 'id' locator strategy

waitForCheckboxToBeDisabled(id)

Waits for checkbox element to become disabled, identified by id locator strategy

Param Type Description
id string Id value of the element based on 'id' locator strategy

selectDropdownItem(parentId, itemIndex)

Select an item in the dropbox element, identified by id locator strategy

Param Type Description
parentId string Id value of the element based on 'id' locator strategy
itemIndex number index value of the dropdown values

waitForPageLoadComplete() ⇒ Promise.<void>

Waits for the page to complete loading/refreshing

Returns: Promise.<void> - Returns true if page has successfully loaded
Throws:

  • Promise.<msg> Returns an error if timed out

waitUntilUrlContains(prefix)

Waits until the URL contains the specified prefix

Param Type Description
prefix string part of the url for verification

waitUntilUrlIs(url)

Waits until the URL of the webpage matches the expected url value

Param Type Description
url string entire URL string to be verifieds

openNewTab(url)

Opens a new tab with specified URL

Param Type Description
url string URL to be opened

validateInNewTabAndClose(callback)

Waits for new tab to open and callback is called on success

Param Type Description
callback function callback function to be called after new tab is opened and validated

waitForElementToBeNotVisible(strategy, locator)

Waits for element to become stale, until timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

waitForElementToBeVisible(strategy, locator)

Waits for element to be attached to the webpage and become visible, until timeout

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy

getBrowserConsoleLogs() ⇒ string

Get browser console logs

Returns: string - - Entire browser logs in preserved state

uploadFile(strategy, locator, filepath)

Custome function to upload a file using an element, identified by specified locator strategy

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
filepath string path of the file to be uploaded

throwErrorWithDetailsIfNotStale(strategy, locator, fxName, error, callback)

Custom function to verify if element is stale and execute callback if yes; if not, fail with message

Param Type Description
strategy string 'id', 'name', 'className', 'xpath', 'css', 'tagName', 'linkText', 'partialLinkText', 'accessibilityId'
locator string value of element to search, corresponding to locator strategy
fxName string name of function
error Object error object with name parameter and message
callback function callback function to be called if error.name is StaleElementReferenceError

waitForCookie(title)

Waits for cookie to be expected value

Param Type Description
title string key name of cookie in browser

getCookie(title)

Returns cookie value

Param Type Description
title string key name of cookie in browser

waitForCookieToClear(title)

Waits for expected cookie to be cleared, until timeout

Param Type Description
title string key name of cookie in browser

waitForCookieToEqual(title, value)

Waits for cookie to be expected value, until timeout

Param Type Description
title string key name of cookie in browser
value string expected value of cookie key

processAndThrowError(error, errorStack)

Error Processor and throws error back up to the runner

Param Type Description
error Object Must be an object so that the method can add additional fields
errorStack any Must be an object so that the method can add additional fields