Nightwatch-Extra

Enhanced nightwatchjs commands and assertions.

Features

nightwatch-extra enhancement includes

  1. An automatical wait for element to be visible (using jquery :visible pseudo) before executing every nightwatch command or assertion (done by injecting sizzlejs).
  2. A base command with wait-for-visible feature for further extension.
  3. A base assertion with wait-for-visible feature for further extension.
  4. A base test for customization.
  5. An easy-to-use sizzlejs selector option.

Usage

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

Command vocabulary

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.

Enhanced command list

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/)

Enhanced assertion list

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)

As-is Supported Nightwatch Vocabulary

All Nightwatch commands and assertions are supported out of the box.

Supported Nightwatch Commands

Supported Nightwatch Assertions

Supported Nightwatch Page Object

  • 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.

Supported Node Assertions

  • fail
  • equal
  • notEqual
  • deepEqual
  • notDeepEqual
  • strictEqual
  • notStrictEqual
  • throws
  • doesNotThrow
  • ifError

Important migration notice

If you're migrating from magellan-nightwatch to nightwatch-extra, please follow the steps

  1. Delete ./node_modules/testarmada-magellan-nightwatch from your project.
  2. In package.json
dependencies:{
    "testarmada-magellan-nightwatch: VERSION   <---- DELETE THIS LINE
    "testarmada-nightwatch-extra: "^1.0.0"     <---- ADD THIS LINE
}
  1. Run npm install again under your project root folder.
  2. 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
]

  1. 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