Enhanced nightwatchjs commands and assertions.
nightwatch-extra enhancement includes
- An automatical wait for element to be visible (using jquery
:visible
pseudo) before executing every nightwatch command or assertion (done by injecting sizzlejs). - A base command with wait-for-visible feature for further extension.
- A base assertion with wait-for-visible feature for further extension.
- A base test for customization.
- An easy-to-use sizzlejs selector option.
In nightwatch.json
add following content
"custom_assertions_path": [
"./node_modules/testarmada-nightwatch-extra/lib/assertions"
],
"custom_commands_path": [
"./node_modules/testarmada-nightwatch-extra/lib/commands"
]
If you're using this repo together with testarmada-magellan, your base test can inherit from the base test by
var BaseTest = require("testarmada-nightwatch-extra/lib/base-test-class");
For full example, please checkout boilerplate-nightwatch
If you're familiar with nightwatch
or are looking to translate nightwatch
examples into nightwatch-extra
, refer to the tables below for equivalent enhanced (i.e. more reliable) versions of nightwatch
commands and assertions.
All commands and assertions are fully compatible with nightwatchjs page object.
Nightwatch-extra Command | Example | Nightwatch Equivalent |
---|---|---|
clickAutomationEl(css selector) | clickAutomationEl("mybutton") | click("[data-automation-id='mybutton']") |
clickEl(css selector) | clickEl(".submitButton") | click(".submitButton") |
getEl(css selector) | getEl(".submitButton") | waitForElementPresent(".submitButton") or waitForElementVisible(".submitButton") |
moveToEl(css selector, xoffset, yoffset) | moveToEl(".submitButton", 10, 10) | moveToElement(".submitButton", 10, 10) |
setElValue(css selector, value) | setElValue(".username", "testarmada") | setValue(".username", "testarmada") |
getElValue(css selector, callback) | getElValue(".user-profile", function(profile){// use profile here}) | getValue(".user-profile", function(profile){// use profile here}) |
getEls(css selector, callback) | getEls(".state-options", function(stats){// use stats here}) | elements("css selector", ".state-options", function(stats){// use stats here}) |
setMaskedElValue(css selector, value, [fieldLength]) | setMaskedElValue(".phone-number", "123456789") | (no nightwatch equivalent) |
waitForElNotPresent(css selector) | waitForElNotPresent(".submitButton") | waitForElementNotPresent(".submitButton") |
getPerformance(url) | getPerformance("http://www.google.com") | Retrieves basic performance metrics using Navigation API (http://www.w3.org/TR/navigation-timing/) |
Nightwatch-extra Assertion | Example | Nightwatch Equivalent |
---|---|---|
assert.elContainsText(css selector, regex or text) | assert.elContainsText(".username", "testarmada") | assert.containsText(".username", "testarmada") |
assert.elNotContainsText(css selector, text) | assert.elNotContainsText(".username", "testarmada") | (no nightwatch equivalent) |
assert.selectorHasLength(css selector, expectedLength) | assert.selectorHasLength(".username", 10) | (no nightwatch equivalent) |
assert.elLengthGreaterThan(css selector, selectUsing, lengthToCompare) | assert.elLengthGreaterThan(".username", "text", 10) | (no nightwatch equivalent) |
All Nightwatch commands and assertions are supported out of the box.
- Please refer to Nightwatch Commands API for a list of supported Nightwatch commands
- Please refer to Nightwatch Assertions API for a list of supported Nightwatch assertions
- All nightwatch-extra commands and assertions fully support nightwatch page object mode. They can be utilized directly if nightwatch page object is being used in your test.
fail
equal
notEqual
deepEqual
notDeepEqual
strictEqual
notStrictEqual
throws
doesNotThrow
ifError
If you're migrating from magellan-nightwatch to nightwatch-extra, please follow the steps
- Delete
./node_modules/testarmada-magellan-nightwatch
from your project. - In
package.json
dependencies:{
"testarmada-magellan-nightwatch: VERSION <---- DELETE THIS LINE
"testarmada-nightwatch-extra: "^1.0.0" <---- ADD THIS LINE
}
- Run
npm install
again under your project root folder. - Make sure your
nightwatch.json
file has the following changes
"custom_commands_path":[
"./node_modules/testarmada-magellan-nightwatch/lib/commands" <---- DELETE THIS LINE
"./node_modules/testarmada-nightwatch-extra/lib/commands" <---- ADD THIS LINE
],
"custom_assertions_path":[
"./node_modules/testarmada-magellan-nightwatch/lib/assertions" <---- DELETE THIS LINE
"./node_modules/testarmada-nightwatch-extra/lib/assertions" <---- ADD THIS LINE
]
- Change parent of your base test class (if there is)
require("testarmada-magellan-nightwatch/lib/base-test-class"); <---- DELETE THIS LINE
require("testarmada-nightwatch-extra/lib/base-test-class"); <---- ADD THIS LINE