Methods
(static) clearCookiesAndDeleteLocalStorage(driver) → {bool}
Clear cookies and delete localStorage.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
Returns:
Returns true once localStorage is cleared.
- Type
- bool
(static) clickWhenClickable(driver, selector, waitMs) → {Promise}
Wait for the clickable element then click it. Timeout occurs after waitMs
if clickable element located by selector is not present.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
waitMs |
number | How long to wait in millisecond. Defaults to 10000. |
Returns:
A promise that will be resolved with true if element
located by selector is successfully clicked, false if
element is not clickable, or rejected if times out waiting
clickable element to present and displayed.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.clickWhenClickable( driver, By.css( 'a.button' ) )
.then( ... );
(static) deleteLocalStorage(driver)
Empty all keys out of the localStorage.
Under the hood invoke window.localStorage.clear().
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
(static) getMediaWithFilename(filename, type) → {Promise}
Get path of example media where filename is filename and media type is type.
This function can be used for testing file upload of various where various
media types is allowed to be uploaded. Under the hood it copies pre-defined
media in this package into filename and returns the file details.
Parameters:
| Name | Type | Description |
|---|---|---|
filename |
String | Full path of filename where new media is going to be created. |
type |
String | Media type. |
Returns:
Promise of file details.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import path from 'path';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.getMediaWithFilename( 'test-upload-image.jpg', 'jpg' ).then( data => {
driver.findElement( By.css( 'input[type="file"]' ) ).sendKeys( data.file );
helper.clickWhenClickable( driver, By.css( '#submit' ) );
} );
(static) isEventuallyPresentAndDisplayed(driver, selector, waitMs) → {Promise}
Checks whether an element located by selector is eventually present and displayed.
Timeout occurs after waitMs if element located by selector is not present and
displayed.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
waitMs |
number | How long to wait in millisecond. Defaults to 10000. |
Returns:
A promise that will be resolved with true value if element
located selector is eventually present and displayed, or
rejected if times out waiting the element to be present
and displayed.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.isEventuallyPresentAndDisplayed( driver, By.css( '#content' ) )
.then( ... );
(static) mouseMoveTo(driver, selector) → {Promise}
Mouse move into element located by selector.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
Returns:
A promise that will be resolved to true if mouse can
be moved to the element located by selector, false
if can not be moved.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
const selector = By.css( '#submit' );
helper.mouseMoveTo( driver, selector ).then( () => {
helper.clickWhenClickable( driver, selector );
} );
(static) scrollDown(driver, waitMs)
Scroll down once by pressing page down key.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
waitMs |
number | Sleep for |
(static) scrollUp(driver, waitMs)
Scroll up once by pressing page up key.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
waitMs |
number | Sleep for |
(static) selectOption(driver, dropdownSelector, optionText) → {Promise}
Select option with text optionText in select element lcoated by dropdownSelector.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
dropdownSelector |
object | Instance of locator, mechanism for locating
an element on the page. For example
|
optionText |
string | Option text. |
Returns:
A promise that will be resolved to true if option can
be selected, or false if not.
- Type
- Promise
(static) setCheckbox(driver, selector) → {Promise}
Check the checkbox element located by selector.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
Returns:
A promise that will be resolved with true if checkbox
element located by selector is checked.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.setCheckbox( driver, By.css( 'input[type="checkbox"]' ) )
.then( ... );
(static) setWhenSettable(driver, selector, value, options) → {Promise}
Set the element's value, located by selector, with value. Timeout occurs
after waitMs if the element located by selector is not present and displayed.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
value |
string | Value to set to the element. |
options |
objec | Optional object where |
Returns:
A promise that will be resolved with true if element's value,
located by selector, is successfully set, false if
element's value is not set, or rejected if times out waiting
the element to present and displayed.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.setWhenSettable( driver, By.css( 'input[name="username"]' ) )
.then( ... );
(static) takeScreenshot(manager, currentTest) → {Promise}
Take a screenshot from currentTest.
The best place to use this is in test.afterEach hook where all tests
are captured.
Parameters:
| Name | Type | Description |
|---|---|---|
manager |
WebDriverManager | Instance of |
currentTest |
Object | Current test. |
Returns:
A promise that will be resolved with undefined once
screenshot is written to manager.config.screenshotsDir.
- Type
- Promise
Example
import test from 'selenium-webdriver/testing';
import { WebDriverHelper as helper } from 'wp-e2e-webdriver';
test.afterEach( 'Take screenshot', function() {
return helper.takeScreenshot( global.__MANAGER__, this.currentTest );
} );
(static) unsetCheckbox(driver, selector) → {Promise}
Uncheck the checkbox element located by selector.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
Returns:
A promise that will be resolved with true if checkbox
element located by selector is unchecked.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.unsetCheckbox( driver, By.css( 'input[type="checkbox"]' ) )
.then( ... );
(static) waitForFieldClearable(driver, selector, waitMs) → {Promise}
Wait for the element value is cleared. Timeout occurs after waitMs if
the element located by selector is not present and displayed.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
waitMs |
number | How long to wait in millisecond. Defaults to 10000. |
Returns:
A promise that will be resolved with true if element's value,
located by selector, is successfully cleared, false if
element's value is not cleared, or rejected if times out waiting
the element to present and displayed.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.waitForFieldClearable( driver, By.css( 'input[name="username"]' ) )
.then( ... );
(static) waitTillNotPresent(driver, selector, waitMs) → {Promise}
Wait for element, located by selector, until not present. Timeout occurs
after waitMs if element located by selector still present.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
waitMs |
number | How long to wait in millisecond. Defaults to 10000. |
Returns:
A promise that will be resolved with true value if element
located selector is eventually not present, or rejected
if times out waiting the element to be not present.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.waitTillNotPresent( driver, By.css( '#content' ) )
.then( ... );
(static) waitTillPresentAndDisplayed(driver, selector, waitMs) → {Promise}
Wait for element, located by selector, until present and displayed. Timeout
occurs after waitMs if element located by selector is not present and
displayed.
Parameters:
| Name | Type | Description |
|---|---|---|
driver |
WebDriver | Instance of WebDriver. |
selector |
object | Instance of locator, mechanism for locating an element
on the page. For example |
waitMs |
number | How long to wait in millisecond. Defaults to 10000. |
Returns:
A promise that will be resolved with true value if element
located selector is present and displayed, or rejected if
times out waiting element to present and displayed.
- Type
- Promise
Example
import { By } from 'selenium-webdriver';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
helper.waitTillPresentAndDisplayed( driver, By.css( '#content' ) )
.then( ... );
(static) writeImage(data, dst) → {unefined}
Write image data to dst.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
String | Buffer | Uint8Array | Date to write. |
dst |
dst | Path of the file where data being written into. |
Returns:
Returns value from fs.writeFileSync which is undefined.
- Type
- unefined
Example
import path from 'path';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
driver.takeScreenshot().then( data => {
const dst = path.resolve( manager.config.screenshotsDir, 'screenshot.png' );
helper.writeImage( data, dst );
} );
(static) writeText(content, dst) → {unefined}
Write text data to dst.
Parameters:
| Name | Type | Description |
|---|---|---|
content |
String | Buffer | Uint8Array | Date to write. |
dst |
dst | Path of the file where data being written into. |
Returns:
Returns value from fs.writeFileSync which is undefined.
- Type
- unefined
Example
import path from 'path';
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
const manager = new WebDriverManager( 'chrome' );
const driver = manager.getDriver();
const dst = path.resolve( process.cwd(), 'browser-log.txt' );
driver.manage().logs().get( 'browser' ).then( logs => {
logs.forEach( log => {
helper.writeText( log.message, dst );
} );
} );