Install Node.js

From nodejs.org:

"Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices."

There are installation packages and instructions for most major Operating systems on its website nodejs.org. Remember to install also the npm tool, which is the node package manager and is distributed with the Node.js installer.

Install Nightwatch

To install the latest version using the npm command line tool, run the following:

npm install nightwatch
  • add -g option to make nightwatch runner available globally in your system.
  • add --save-dev option to save nightwatch as a devDependency in your package.json.

Install Browser Drivers

Depending on your target browsers, you will need one or more specific WebDriver packages. You can install them from NPM or download separately.

GeckoDriver

GeckoDriver can be simply installed from NPM and no further configuration is necessary.

npm install geckodriver --save-dev

Alternatively, it can be downloaded from the GeckoDriver Releases page on GitHub. Release notes are also available there.

ChromeDriver

Same as GeckoDriver, ChromeDriver can be simply installed from NPM and no further configuration is necessary.

Alternatively, it can be downloaded from the ChromeDriver Downloads page.

npm install chromedriver --save-dev

Microsoft Edge Driver

Follow the Download Microsoft Edge Driver section on the official Microsoft Edge documentation page to download the Edge Driver.

For more instructions on using Microsoft Edge for testing with Nightwatch, follow this page.

SafariDriver

The safaridriver binary is already installed on recent versions of Mac OS, however some manual configuration is needed before tests can be run against Safari.

You will need to run the following once, before using the safaridriver:

safaridriver --enable

More details are available on the Apple Developer website. See also this tutorial: Testing with WebDriver in Safari.

Install Selenium Server

Using Selenium Standalone Server used to be the de-facto standard for managing the various browser drivers and services, but starting with Nightwatch 1.0 is no longer required, nor is it recommended for testing against a single browser.

Install Java
Selenium Server is a Java application, which means you will also need to have the Java Development Kit (JDK) installed, minimum required version is 7. You can check this by running java -version from the command line.

Selenium server can be downloaded in the following two ways:

From NPM

The easiest way to install the Selenium Server is from NPM using the @nightwatch/selenium-server package which is maintained by the Nightwatch team. Nightwatch automatic configuration is already prepared for usage with this package against Chrome, Firefox, and Internet Explorer.

By default, the NPM package will install Selenium version 4.

npm install @nightwatch/selenium-server

If Selenium version 3 is needed, run:

npm install @nightwatch/selenium-server@3

For more details, see our selenium-server-ja-download Github page.

From Selenium GitHub Releases

You can find the latest Selenium Server stable and other versions on the Selenium GitHub Releases page.

Download the selenium-server-{VERSION}.jar file and place it on the computer with the browser you want to test. In most cases this will be on your local machine and typically inside your project's source folder. A good practice is to create a separate subfolder (e.g. bin) and place it there as you might have to download other driver binaries if you want to test multiple browsers.

Configure the Selenium Server

To use Nightwatch with Selenium Server, you can configure it as below. No additional config is required if you use @nightwatch/selenium-sever package to download Selenium.

selenium_server: {
  // Selenium Server is running locally and is managed by Nightwatch
  // Install the NPM package @nightwatch/selenium-server 
  //  or download the selenium server jar file from https://github.com/SeleniumHQ/selenium/releases/
  selenium: {
    start_process: true,
    port: 4444,
    server_path: '', // Leave empty if @nightwatch/selenium-server is installed
    command: 'standalone', // Selenium 4 only
    cli_args: {
      // Configure the paths to individual drivers below:
      //
      // 'webdriver.gecko.driver': '',
      // 'webdriver.chrome.driver': ''
      // 'webdriver.edge.driver': ''
    }
  },
  webdriver: {
    start_process: false,
    default_path_prefix: '/wd/hub'
  }
}

Note:

If you are using selenium-server jar file instead (downloaded from Selenium website or Selenium GitHub Releases), set the server_path property of selenium to point to the location of the jar file.

Running Selenium Automatically

If the server is on the same machine where Nightwatch is running, it can be started/stopped directly by the Nightwatch Test Runner.

Running Selenium Manually

To run the Selenium Server manually, from the directory with the jar run the following:

java -jar selenium-server-standalone-{VERSION}.jar

In this case, set the start_process property of selenium in the Nightwatch config above to false, so that Nightwatch does not try to start Selenium server automatically.

Using Selenium Standalone Server

For viewing all the run-time options, run the previous command adding the -help:

java -jar selenium-server-standalone-{VERSION}.jar -help

More info about running the Selenium Server can be found here on the official Selenium Docs

Improve this article