Getting started with Nightwatch takes only a few short minutes. Here's how to be up and running with your first end-to-end test.
Make sure Node is installed on the system. The version used for this tutorial is v16.14.2
Nightwatch can be installed with just one command line, either as a new project or in an existing location.
1. As a new project:
To setup Nightwatch as a new project, simply run:
npm init nightwatch
2. In an existing project:
y when you see the prompt to install create-nightwatch
This installs Nightwatch, asks your preferences and sets up the
nightwatch.conf.js file based on your preferences as shown below
Run on Local/Remote (Cloud)
You can configure Nightwatch to run locally on your machine, remotely on a cloud machine or both
For remote testing, host and port details will be automatically added in case you select
Sauce Labs. However if you select to run on your own remote selenium server or any other cloud provider, you will have to manually configure the host & port details in the
You can pick the browsers you'll be testing on, and the config will be automatically created for them. We provide a multi-selection option so you can pick as many browsers you want to test on. You can also use the selenium-server when testing on the local machine.
Next you can name the folder where you want the tests to reside. The default value is tests.
Add the base URL that the tests will run against. This preference will default to http://localhost
Once you select this preference, Nightwatch setup will begin. It will also generate sample tests for you to get started.
If you are running from a Mac, safaridriver is present by default but must be enabled. You will be presented with the following option.
Run your first end-to-end test
Once your setup is done, you can run tests with this command
npx nightwatch tests/specs/basic/ecosia.js --env safari
The output should look similar to this:
Use the Google Chrome DevTools Recorder
Alternatively, Nightwatch provides tools to help you get started by recording your test actions on screen and generate Nightwatch test scripts automatically. See Create Nightwatch test using Google Chrome DevTools Recorder for more information.