nightwatch icon indicating copy to clipboard operation
nightwatch copied to clipboard

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack

Nightwatch.js

npm Node.js CI codecov npm package Discord Node Support

Nightwatch.js Schematic Logo

HomepageDeveloper GuideAPI ReferenceAboutBlog

Nightwatch is an integrated testing framework powered by Node.js and using the W3C Webdriver API. It is a complete testing solution developed at BrowserStack and which can be used for:

☑️ end-to-end testing of web applications and websites
☑️ component testing in isolation (React / Vue)
☑️ Node.js unit and API testing

🚀 Nightwatch v2

What's New | Release Notes | Discussions

We're delighted to announce that Nightwatch v2 is now available in the public NPM channel. Read the what's new docs page for an overview of the new features, improvements, and important changes.

Install with:

npm i nightwatch

⚙️ Get started in 60 seconds

nightwatch-cli-gif

1. Install Nightwatch from NPM

# from your existing project's root dir
$ npm init nightwatch

# if you want to initialize a new project
$ npm init nightwatch path/to/new/project

2. Answer a few questions about your preferred setup:

  • What is your Language - Test Runner setup?
  • Where do you want to run your e2e tests?
  • Where you'll be testing on?
  • Where do you plan to keep your end-to-end tests?
  • What is the base_url of your project?

Nightwatch will do the entire setup for you based on your answers.

3. Run a Demo Test:

Nightwatch comes with a few examples, which are automatically copied to your Nightwatch project during the setup and can also be used as boilerplate to write your own tests on top of them.

You can follow the instructions given at the end of the setup to run your first test with Nightwatch.

image

🗒 Examples

Examples below are written using Nightwatch 2.

Search for the term "Nightwatch.js" using:

Google search using page objects

ToDo App on AngularJs homepage

You can run any of the examples by simply referring to the examples folder like below:

npx nightwatch examples/tests/angularTest.js

CucumberJS examples

The bundled config file which is auto-generated by Nightwatch on the first run (only if one is not already present in the project), contains configuration and examples for running the CucumberJS examples immediately, using the following:

npx nightwatch --env cucumber-js

Manually Download Browser Drivers

Nightwatch uses a WebDriver compatible server to control the browser. WebDriver is a W3C specification and industry standard which provides a platform and HTTP protocol to interact with a browser.

Nightwatch includes support for automatically managing the following services:

ChromeDriver

GeckoDriver

Selenium Standalone Server

  • allows managing multiple browser configurations in one place and also to make use of the Selenium Grid service;
  • the selenium server jar file selenium-server-standalone-4.x.x.jar can be downloaded from the Selenium releases page: https://selenium-release.storage.googleapis.com/index.html

It's important to note that, while the Selenium Server was required with older Nightwatch versions (v0.9 and prior), starting with version 1.0 the Selenium Server is no longer necessary.

Specific WebDriver setup guides can be found on the Docs website. Legacy Selenium drivers setup guides along with debugging instructions can be found on the Wiki.

Nightwatch unit tests

The tests for Nightwatch are written using Mocha.

1. Clone the project

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

2. Run tests

To run the complete test suite:

$ npm test

To check test coverage, run the command:

$ npm run mocha-coverage

and then open the generated coverage/index.html file in your browser.

🦉 About Nightwatch

Nightwatch was initially built by @pineviewlabs - an independent software consultancy based in Oslo, Norway, with help from contributors. In mid 2021, Nightwatch has become a part of the @BrowserStack family and it is being developed further at the BrowserStack Open-source Program Office. Read more on our blog.

We are thankful for everyone who supported Nightwatch on the OpenCollective platform.

Licence

MIT