Skip to content

Guide · Open source

How to use Nightwatch: setup, first test and key features

Updated · written with AI from the project's own documentation and checked against our catalogue data

Nightwatch is an open-source testing framework for JavaScript and Node.js that runs automated checks against web applications and websites in real browsers. It controls browsers through the W3C WebDriver standard, so tests can simulate what a user does, such as clicking and typing. This guide shows you how to set up a project, run the demo test, and understand what else Nightwatch covers.

Nightwatch.jsnightwatchjs/nightwatch · ★ 12k · MIT

Quick start

  1. 1Check Node.js. Confirm Node.js is installed, since it is the prerequisite named in the README.
  2. 2Run the setup command. From your project root, run npm init nightwatch@latest. Pass a path to start a new project in another folder.
  3. 3Answer the setup questions. Choose your language and test runner setup, target platforms, test location and base_url.
  4. 4Run the demo test. Follow the instructions printed at the end of setup to run the example test that Nightwatch copied into your project.
  5. 5Write your own tests. Use the demo examples as boilerplate and add tests that click, type and check page behaviour.
  6. 6Add other test types if needed. Enable component, visual, API, accessibility or mobile testing as your project requires.

What Nightwatch is and who it is for

Nightwatch is an integrated testing framework powered by Node.js. The project's README describes it as a complete testing solution developed at BrowserStack. It can be used for end-to-end testing of web applications and websites, component testing in isolation for React, Vue, Storybook and Angular, Node.js unit, visual regression, accessibility and API testing, and native mobile app testing on Android and iOS.

  • Good fit: JavaScript or Node.js teams who want end-to-end browser tests
  • Good fit: projects that need component testing for React, Vue, Angular or Storybook
  • Good fit: developers testing native Android or iOS apps through Appium
  • Poor fit: teams wanting a no-code testing tool, because tests are written in code
  • Poor fit: projects that need no browser or driver configuration, since WebDriver-based tooling requires it

What you need before you install Nightwatch

The only prerequisite named in the source is Node.js. Install commands in the README use npm, so you will need npm available alongside Node.js. Nightwatch tests drive real browsers through WebDriver, so you should expect to have browsers and their drivers configured as part of your setup.

Install Nightwatch and initialize a project

Run the setup command from your existing project's root directory. The setup asks questions about your preferred configuration and then does the setup for you. To start a new project in a specific folder, pass a path to the same command.

  • Language and test runner setup
  • Where you want to run your end-to-end tests
  • Which browsers or platforms you will test on
  • Where you plan to keep your end-to-end tests
  • The base_url of your project
npm init nightwatch@latest

Run the demo test

Nightwatch copies a few example tests into your project during setup. You can run them as they are, or use them as boilerplate for your own tests. Follow the instructions printed at the end of the setup to run your first test.

Other things you can test with Nightwatch

Beyond end-to-end tests, the README lists several areas. Component testing mounts components in the browser so they can be tested in isolation. Visual regression testing captures screenshots, compares them with a baseline, shows differences in a report, and lets you approve changes. API testing covers request and response assertions, viewing API tests in the HTML report, and a mock server. Accessibility testing packages the aXe-core package from Deque Systems as a plugin for WCAG checks.

For native apps, Nightwatch works with Appium to run end-to-end functional tests on Android and iOS devices.

  • Component testing: React, VueJS, Angular, Storybook
  • Visual regression testing on desktop and mobile browsers
  • API testing with request and response assertions
  • Accessibility testing with aXe-core, covering 90 types of checks as stated in the README
  • Native mobile testing via Appium

Contribute to or test the Nightwatch project itself

If you want to work on Nightwatch's own code, the README explains how to clone the repository and install its dependencies. Its unit tests are written with Mocha. Contribution guidelines are in CONTRIBUTING.md.

git clone https://github.com/nightwatchjs/nightwatch.git cd nightwatch npm install npm test

What people use it for

  • End-to-end tests that click through a web app and check the results in real browsers
  • Component tests for React, Vue, Angular or Storybook components mounted in isolation
  • Visual regression checks that compare screenshots against an approved baseline
  • Accessibility checks against WCAG using the aXe-core plugin
  • Native Android and iOS app tests run through Appium

Frequently asked questions

Is Nightwatch free to use?

Nightwatch is released under the MIT licence, as stated in the README and the LICENSE.md file. The MIT licence permits use under its terms; check LICENSE.md for the full text.

What do I need to install Nightwatch?

The README names Node.js as the prerequisite. You install Nightwatch with the npm init nightwatch@latest command from your project root.

Do I need to write code to use Nightwatch?

Yes. The README says tests are written in code, so Nightwatch is not a no-code testing tool.

Can Nightwatch test React, Vue or Angular components?

Yes. The README says Nightwatch supports component testing for React, VueJS, Angular and Storybook, by mounting components in the browser.

Can Nightwatch test mobile apps?

Yes, for native apps on Android and iOS. The README says this works via Appium, combined with Nightwatch's developer experience.

How does Nightwatch compare to Playwright, Cypress, WebdriverIO or Selenium?

The source does not include a comparison, so this guide cannot rank them. Nightwatch uses the W3C WebDriver standard and is built on Node.js; compare that with your team's needs for JavaScript, browsers and mobile testing.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Nightwatch suits JavaScript and Node.js teams who want end-to-end browser tests, and possibly component, API, visual or accessibility tests, in one framework. Teams that want no-code tools, a setup with no browser or driver configuration, or a non-JavaScript unit test stack should look at other options.

Install options & downloads