Getting started with Nightwatch takes only a few short minutes. You can perform the following types of testing with Nightwatch
- End to end testing of web apps on desktop & mobile browsers
- Component testing with top frameworks such as React, Vue, Storybook & Angular
- Mobile app testing on Android & iOS
- API testing
- Visual regression testing (VRT)
- Accessibility testing
For all types of testing, you have to start by installing Nightwatch itself. Let’s begin!
Make sure Node is installed on the system.
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:
Press 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
Answer the simple set of questions to complete the Nightwatch installation. In case you need more info around these questions please refer to the guide below. Otherwise please skip to Run your end to end tests section post completion of installation.
This will setup Nightwatch along with all the required dependencies for the type of testing selected. Nightwatch base version will be installed irrespective of the choice.
Test runner & Language
You can pick the browsers you'll be testing on, and the config will be automatically created for them.
Next you can name the folder where you want the tests to reside. The default value is tests.
This is a very important configuration that should be used as a variable in your tests so that you can switch between different testing environment & URLs with a simple config change. This preference will default to http://localhost
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
Allow Nightwatch to collect anonymous metrics. The preference will default to
no as we respect our user’s privacy.
Run tests on Mobile web
Nightwatch supports running of tests on real and virtual mobile devices. Nightwatch will also take care of the setup of all underlying SDK, libraries & virtual devices.
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 example tests with this command
npx nightwatch ./nightwatch/examples
The output should look similar to this:
View the report
Simply, copy-paste the HTML path at the end of the output in your browser address bar to view the report
Congratulations! You have installed Nightwatch, run a test & viewed the HTML report.
Recommended Next Steps
Now that you have installed Nightwatch