Nightwatch.js 1.3 New Features, Installation Guide, and Usage Examples
This article introduces Nightwatch.js 1.3, outlines its new BDD interface, additional assertions and APIs, provides step‑by‑step installation of Nightwatch and browser drivers via npm, explains CLI options, demonstrates running a sample test, and offers guidance on unit testing and example projects.
Nightwatch.js is an end‑to‑end testing framework built on Node.js that uses the W3C WebDriver protocol (formerly Selenium) to automate web applications. Version 1.3 adds several notable features:
BDD describe interface allowing tests to be written in BDD style without extra configuration.
New assertion assert.not (e.g., browser.assert.not.elementPresent('.not_present') ).
Additional APIs such as getElementProperty , domPropertyContains , domPropertyEquals , and .property .
New CLI options like --headless to run browsers in headless mode and --timeout to set a global retry timeout for failed assertions.
Installation and Startup
npm install nightwatch --save-devInstall the required browser drivers:
npm install geckodriver --save-dev npm install chromedriver --save-devOr install everything in one command:
npm i nightwatch geckodriver chromedriver --save-devRunning a Demo Test
Nightwatch includes an example folder with sample tests. To run a basic test that searches for "nightwatch" on Ecosia.org and verifies the first result, execute:
./node_modules/.bin/nightwatch node_modules/nightwatch/examples/tests/ecosia.jsWindows users may need to run:
node node_modules/.bin/nightwatchManual Browser Driver Download
Nightwatch can manage WebDriver services automatically, but you can also download drivers manually:
ChromeDriver – download from ChromeDriver downloads . From version 75 onward, W3C protocol is default; to use JSONWire, set w3c: false in chromeOptions :
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: { w3c: false }
}GeckoDriver – download from GeckoDriver releases for Firefox.
Selenium Standalone Server – useful for managing multiple browsers and Selenium Grid; download the JAR from the Selenium release page. Note that Nightwatch no longer requires Selenium from version 1.0 onward.
Examples
The example folder demonstrates various Nightwatch features. Additional tests are available in the nightwatch-website-tests repository.
Nightwatch Unit Tests
Nightwatch tests are written using Mocha. To run the full test suite:
git clone https://github.com/nightwatchjs/nightwatch.git
cd nightwatch
npm install npm testTo generate coverage reports:
npm run mocha-coverageOpen the generated coverage/index.html in a browser to view results.
Nightwatch Usage Example
An example repository ( nightwatch-e2e ) shows how to organize directories, configure global and local environments, and test the Nightwatch website itself.
Conclusion
If you need to perform web automation testing with JavaScript, Nightwatch.js is a highly recommended choice for writing reliable end‑to‑end test cases.
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.