How to setup Nighwatch in a multi-OS configuration


This article is a follow up of

Nighwatch in a team with multiple Operating systems

In the real world, you may encounter a team running several OSes : Windows, MacOS, Linux, etc. When you want to run an acceptance test, it must be runnable under each OS.
Nightwatch uses Selenium as an underlying browser runner, however, the browser driver has to be different under each OS : you do not want to run a Windows version of Chrome whenever Nighwatch runs under MacOS, and vice-versa.

Fun fact : you do NOT need the following setup if you are only running acceptance tests under Firefox (MacOS, or Windows). Only Chrome requires the following setup.

The setup

First, you need to grab a Selenium Chrome driver for windows. The latest driver is available here. Put this under (your_preferred_nighwatch_path)/lib/chromedriver.exe : the other chromedriver for MacOS/Linux is already available under our node_modules folder.

Second, you need to create a nightwath.conf.js file, this is where you will split the drivers :

module.exports = (function (settings) {

  //Setting chromedriver path at runtime to run on different architectures
  if (process.platform === "darwin") {
    settings.selenium.cli_args[""] = "./node_modules/chromedriver/bin/chromedriver";
  else if (process.platform === "win32" || process.platform === "win64") {
    settings.selenium.cli_args[""] = "nw/lib/chromedriver.exe";

  return settings;


Third, you need to create a nightwatch.js file. This is a runner, and this is mandatory if you want to run tests under Windows, runner.js is already bundled with Nightwatch :

Wrapping up

Now that we have split our drivers, you can get rid of the definition under your nightwatch.json selenium configuration, because it will be automatically completed :

"selenium" : {
			"start_process" : true,
			"server_path" : "nw/lib/selenium-server-standalone-2.53.0.jar",
			"log_path" : "nw/logs",
			"host" : "",
			"port" : 4444,
			"cli_args" : {
				"" : "", // empty !
				"" : ""

Ultimately, go back to your package.json, update the scripts field and tell Nightwatch to use our newest splitter :

"scripts": {
    "test": "node nightwatch.js -c nightwatch.conf.js"

We are done, just run it :

npm test

Under MacOS/Linux, ./node_modules/chromedriver/bin/chromedriver will run, under Windows, nw/lib/chromedriver.exe will run instead.

Happy testing !

Laurent, Développeur Javascript  @JS-Republic

JS-REPUBLIC est une société de services spécialisée dans le développement JavaScript. Nous sommes centre de formation agréé. Retrouvez toutes nos formations techniques sur notre site partenaire dédié au Training


No comments

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *