Ensure API

Overview

The new .ensure API available since Nightwatch 2.0 is mapping the existing until module from Selenium.

It works similar to the existing .assert library and provides much of the same functionality, but it might offer an extra level of flexibility. It may also be more familiar to users already working with the until api from Selenium..

Basic Example:
describe('demo test for .ensure', function() {
  
it('basic test', function(browser) { browser .url('https://nightwatchjs.org') .ensure.titleMatches(/Nightwatch\.js/) .ensure.elementIsVisible('#index-container') }); });

Available Assertions

.ableToSwitchToFrame(frame)

Ensures that the Nightwatch WebDriver client is able to switch to the designated frame.

Parameters:
Name Type description
frame Number|WebElement|By The frame identifier.

.alertIsPresent()

Creates a condition that waits for an alert to be opened.

Parameters:
None

.elementIsDisabled(element)

Creates a condition that will wait for the given element to be disabled.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsEnabled(element)

Creates a condition that will wait for the given element to be enabled.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsNotSelected(element)

Creates a condition that will wait for the given element to be deselected.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsNotVisible(element)

Creates a condition that will wait for the given element to be in the DOM, yet not displayed to the user.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsNotVisible(element)

Creates a condition that will wait for the given element to be in the DOM, yet not displayed to the user.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsSelected(element)

Creates a condition that will wait for the given element to be selected.

Parameters:
Name Type description
element WebElement The element to test.

.elementIsVisible(element)

Creates a condition that will wait for the given element to be displayed.

Parameters:
Name Type description
element WebElement The element to test.

.elementLocated(locator)

Creates a condition that will loop until an element is found with the given locator.

Parameters:
Name Type description
locator By The locator to use.

.elementTextContains(element, substr)

Creates a condition that will wait for the given element's text to contain the given substring.

Parameters:
Name Type description
element WebElement The element to test.
substr String The substring to search for.

.elementTextIs(element, text)

Creates a condition that will wait for the given element's text to equal the given text.

Parameters:
Name Type description
element WebElement The element to test.
text String The expected text.

.elementTextMatches(element, regex)

Creates a condition that will wait for the given element's text to match a given regular expression.

Parameters:
Name Type description
element WebElement The element to test.
regex RegExp The regular expression to test against.

.elementsLocated(locator)

Creates a condition that will loop until at least one element is found with the given locator.

Parameters:
Name Type description
locator By The locator to use.

.stalenessOf(element)

Creates a condition that will wait for the given element to become stale. An element is considered stale once it is removed from the DOM, or a new page has loaded.

Parameters:
Name Type description
element WebElement The element that should become stale.

.titleContains(substr)

Creates a condition that will wait for the current page's title to contain the given substring.

Parameters:
Name Type description
substr String The substring that should be present in the page title.

.titleIs(substr)

Creates a condition that will wait for the current page's title to match the given value.

Parameters:
Name Type description
substr String The expected page title.

.titleMatches(regex)

Creates a condition that will wait for the current page's title to match the given regular expression.

Parameters:
Name Type description
regex RegExp The regular expression to test against.

.urlContains(substrUrl)

Creates a condition that will wait for the current page's url to contain the given substring.

Parameters:
Name Type description
substrUrl String The substring that should be present in the current URL.

.urlIs(url)

Creates a condition that will wait for the current page's url to match the given value.

Parameters:
Name Type description
substrUrl String The expected page url.

.urlMatches(regex)

Creates a condition that will wait for the current page's url to match the given regular expression.

Parameters:
Name Type description
regex RegExp The regular expression to test against.