SeleniumDriver

SeleniumDriver

SeleniumDriver helper for better E2E tests

Constructor

new SeleniumDriver(options)

Create a new SeleniumDriver object

Source:
Parameters:
Name Type Description
options DriverOptions

Options to initialize this driver

Methods

_matchText(search, exact) → {string}

Construct dynamic statement depending on search type for a positive match

Source:
Parameters:
Name Type Description
search string | RegExp

String to base statement construction

exact boolean

If exact use wording is instead of contains

Returns:
Type:
string
  • Constructed statement

_matchTextNot(search, exact) → {string}

Construct dynamic statement depending on search type for a negative match

Source:
Parameters:
Name Type Description
search string | RegExp

String to base statement construction

exact boolean

If exact use wording was not instead of did not contain

Returns:
Type:
string
  • Constructed statement

_pagePath(page)

Ensure page begins with a slash

Source:
Parameters:
Name Type Description
page string

(async) click(selector)

Click an element specified by css selector

Source:
Parameters:
Name Type Description
selector string

CSS selector to be clicked

Throws:
  • Unable to click selector: '${selector}'
Type
Error

(async) elementSelector(element) → {string}

Build accurate element selector based on DOM attributes

Source:
Parameters:
Name Type Description
element selenium-webdriver.WebElement

Expects selenium-webdriver.WebElement

Returns:
Type:
string
  • ${tag}#${id}.${class}

(async) error(msg)

Handle error with msg. Save browser logs and screenshot to DriverOptions.debugDirectory

Source:
Parameters:
Name Type Description
msg string

Message for this error. Used for debug dir name and thrown error message

Throws:
  • msg + debug info
Type
Error

(async) expectElement(selector, contentopt, exactopt) → {selenium-webdriver.WebElement}

Wait for element specified by css selector and optional content.

Source:
Parameters:
Name Type Attributes Default Description
selector string

CSS selector of expected element

content string | RegExp <optional>

Optional content to also be expected within element text

exact boolean <optional>
false

If true and content is a string, then expect element with text exactly content

Throws:
  • No element with selector: '${selector}'
Type
Error
Returns:
Type:
selenium-webdriver.WebElement

(async) expectPage(page, exactopt)

Wait for current path to be, match, or contain page

Source:
Parameters:
Name Type Attributes Default Description
page string | RegExp

Page path to wait for

exact boolean <optional>
false

If true and page is a string, then expect exact full path

Throws:
  • Page did not match: '${page}'
Type
Error

(async) expectStale(element)

Wait for specified element to become stale

Source:
Parameters:
Name Type Description
element selenium-webdriver.WebElement

Expects selenium-webdriver.WebElement

Throws:
  • Element is not stale: '${await this.elementSelector(element)}'
Type
Error

(async) expectTitle(title, exactopt)

Wait for page title to be, contain, or match title

Source:
Parameters:
Name Type Attributes Default Description
title string | RegExp

Title to wait for

exact boolean <optional>
false

If true and title is a string, then wait until page title is exactly title

Throws:
  • Title did not match: '${title}'
Type
Error

(async) fillIn(selector, value, enteropt)

Fill in an element with value specified by css selector

Source:
Parameters:
Name Type Attributes Default Description
selector string

CSS selector of element to receive keys

value string

Value to be sent to element as keys

enter boolean <optional>
false

Flag to also send the ENTER key after value

Throws:
  • Unable to send keys to selector: '${selector}'
Type
Error

(async) quit()

Quit this driver instance

Source:

(async) scrollTo(element)

Scroll to element

Source:
Parameters:
Name Type Description
element selenium-webdriver.WebElement

WebElement to scroll to

(async) select(selector, value)

Select an option with value or text value specified by css selector

Source:
Parameters:
Name Type Description
selector string

CSS selector of <select> element to pick from

value string

Value (or text) of an <option> element to be selected

Throws:
  • Unable to select value/text: '${value}' from selector: '${selector}'
Type
Error

(async) start()

Start this driver instance. Delete Cookies and visit homepage (see DriverOptions.homePagePath)

Source:

(async) visit(page)

Visit specified page

Source:
Parameters:
Name Type Description
page string

Path of page to visit