With just one command, set up everything to run Nightwatch tests in under 60 seconds. Our new onboarding client aims to provide a powerful onboarding experience to the developers setting up Nightwatch for the first time or in their existing project. Learn how to set up the config, and automatically install the webdrivers with the required packages.
Running it
It all starts with the command npm init nightwatch
This is an npm alias for using npx create-nightwatch
. The npx
is a command for executing package binaries without downloading to the local dependency. npm then installs the package in a cache and runs the binary. If you are starting a new project, you can also run npm init nightwatch <directory>
.
The Flow of Choices
The setup is based on a list of questions to accommodate a variety of use cases.
Test Runner
Nightwatch also supports other test runners. You can also pick Mocha or Cucumber as a test runner apart from Nightwatch.
JavaScript / Typescript
Nightwatch supports typescript for test files after v1.6.0. So you can choose to have the test setup in Javascript or Typescript.
Local / Remote
You can set up the config and downloads based on if you're going to be running the test locally or on a remote machine or on both.
Browser Selection
You can pick the browsers you'll be testing on, and the config will be 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.
If you are running from a Mac, safaridriver is present by default but must be enabled.
For remote testing, you should provide the host address and port of the remote machine.
Other parts
Apart from the fundamental differences in the ways you test, we also keep adding other extra configs you can add in the questionnaire. As of May '22 the list is as follows.
- Directory location for the end-to-end tests
- the
base_url
of your project - Using the
--generate-config
to create only the config and not download any dependencies
Result
If --generate-config
is not provided, the script installs the necessary packages.
For local tests, the script also installs the wedrivers based on your browser selection.
By default, the configuration file nightwatch.conf.js
is generated and examples at tests/nightwatch-examples
. If the nightwatch.conf.js
is already present then you can choose to overwrite the existing config file or to create a new one.
Then you can run the examples with this command.
npx nightwatch ./tests/nightwatch-examples
npm init nightwatch
This blog was orginaly posted in the Nightwatch Blog.