How To Install NightWatch And Webdrivers For Test Automation

How To Install NightWatch And Webdrivers For Test Automation

Not Just A Simple Download

Installing NightWatch isn’t just a simple download. You want to use NightWatch in a way that other testers, developers, and automation systems can easily install over and over again.

Below, we’ll go over the few easy steps to install NightWatch. We’ll learn:

  • How to download Node
  • How to create a package.json
  • How to “npm install” NightWatch and webdrivers
  • How to create the initial nightwatch.conf.js file

After following these steps, you will be ready to start writing tests.

Download Node

Go to Node.js’s website and download the Node package for your OS.

https://nodejs.org/en/download/

Verify that Node is installed.  From the command line, run:

 

node --version

You should see something similar to:

C:\Users\User>node --version
v12.16.1

Node Package Manger (npm)

Included with Node is the Node Package Manger (npm).

C:\Users\User>npm --version
6.14.3

“npm” let’s you install packages from the Node package repository online. NightWatch and the webdrivers we want live in this repository.

Create a package.json

Create a default “package.json” file. This will allow you to reinstall all the packages with just a simple “npm install” command. This is how you want to set up your directory for reusable test automation. Anyone can download your source code and just type “npm install” to get everything you set up in your package.json file.

Create your default file:

npm init -y

This will create a package.json file with all the default settings.

Install NightWatch’s node module

npm install nightwatch --save-dev

This will download and install nightwatch under the “node_modules” directory in your folder. The “–save-dev” part will create an entry for NightWatch in the package.json file.

To verify NightWatch is installed in your folder

./node_modules/.bin/nightwatch --version

Alternatively, you can use “npx” to run items you’ve installed via npm.

npx nightwatch --version

Install Chrome and Firefox webdrivers

npm install chromedriver --save-dev
npm install geckodriver --save-dev

“chromedriver” is for Chrome. “geckodriver” is for Firefox.

Both of these webdrivers will be installed under “node_modules” and have entries in package.json

Re-install Everything?

If you need to re-install everything, all you need to do is navigate to the folder with your “packages.json” and run the following.

npm install

This will look at the entries in the package.json file and install them under node_modules again.

Create NightWatch Config File

Finally, create your initial config file for NightWatch: nightwatch.config.js. All you have to do is run NightWatch. It will automatically generate this file for you.

npx nightwatch

You should see the following output.

C:\Users\User\foo>npx nightwatch
No config file found in the current working directory, creating nightwatch.conf.js in the current folder...
   Error: No test source specified, please check configuration.
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

Now, you will have your basic nightwatch.conf.js file in that directory. This file still needs more setup to run tests, but you now have the basics needed to get started testing with NightWatch

Summary

  • Install Node
  • Create package.json
  • Install NightWatch
  • Install WebDrivers
  • Create your initial nightwatch.conf.js file