nightwatch: Starting ChromeDriver: cannot resolve path to chromedriver in Windows environment

Overview

Hi all, So I was following the instructions from nightwatchjs.org/gettingstarted, and setup nightwatch in one of my projects. It seems that running nightwatch in a Windows environment produces the following error:

An error occurred while trying to start ChromeDriver: cannot resolve path: "./node_modules/.bin/chromedriver".
Please check that the "webdriver.server_path" config property is set correctly.

This might not only be a chromedriver issue, see the Environment section below. If it is, I can open this issue over there.

I am also not the only one who has seen this issue: #1960

Test Repo

I have made a bare minimum repo with instructions that produces the error here: https://github.com/chriswoodle/nightwatch-windows-chromedriver-bug

Environment

Chromedriver: 2.45.0 Node: 8.12.0 NPM: 6.4.1 OS: Windows 10 1809

I can confirm that this is not an issue in at least MacOS.

I can also confirm that this error happens on other Windows machines, not the only environment described above.

It might not be a chromedriver issue, since chromedriver can be invoked from npm scripts without error.

package.json

{
  ...
  "scripts": {
    "chromedriver": "chromedriver -v"
  }
}

=>

ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387)

Full error

npm run nightwatch

> universal-ws-tools@ nightwatch C:\Users\Super\git\universal-ws
> nightwatch ./test/browser/nightwatch.js --verbose

 Starting ChromeDriver on port 9515...

An error occurred while trying to start ChromeDriver: cannot resolve path: "./node_modules/.bin/chromedriver".
Please check that the "webdriver.server_path" config property is set correctly.

 ChromeDriver process closed.
 Wrote log file to: C:\Users\Super\git\universal-ws\chromedriver.log.

Thanks for your help!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I have the same issue on Windows with http://nightwatchjs.org/gettingstarted. And finaly got this to work with this nightwatch.conf.js:

const chromedriver = require("chromedriver");
module.exports = (function (settings) {
  settings.test_workers = false;
  settings.webdriver.server_path = chromedriver.path;
  return settings;
})(require("./nightwatch.json"));

Just got chromedriver path property and set webdriver.server_path with that property.

After experiencing this problem, myself, I came across this Issue. Many thanks to @dvalejo and @chriswoodle, as I found both:

  • A way to solve this using a generic function
  • A way to solve this without nightwatch.conf.js

Solution 1: nightwatch.conf.js

const gecko = require("geckodriver");
const selenium = require("selenium-server");
const chrome = require("chromedriver");
module.exports = (function (settings) {
  // console.log('Firefox Path:\r\n', gecko.path);
  settings.test_workers = false;
  settings.test_settings.chrome.webdriver.server_path = chrome.path;
  settings.test_settings.firefox.webdriver.server_path = gecko.path;
  return settings;
})(require("./nightwatch.json"));

By overriding the test environments, you don’t have to a) detect the current environment or b) have multiple conf.js files. See that commented out .log(). Leads to…

Solution 2: using nightwatch.json only

Inspecting the .path showed that nightwatch is looking specifically for the .exe file. It does not accept the .cmd or non-extension file. Pointing your test environments directly to the .exe solved most issues almost immediately. Here is my nightwatch.json file.

{
    "src_folder": ["test"],
    "webdriver": {
        "start_process": true
    },

    "test_runner": "mocha",
    "test_settings": {
        "default": {
        },

        "chrome": {
            "silent": false,
            "selenium_port": 9515,
            "selenium_host": "localhost",
            "webdriver" : {
                "server_path": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
                "host": "localhost",
                "port": 9515
            },
            "desiredCapabilities": {
                "browserName": "chrome"
            }
        },

        "firefox": {
            "selenium_port": 4444,
            "selenium_host": "localhost",
            "webdriver": {
                "server_path": "node_modules/geckodriver/geckodriver.exe",
                "silent": false,
                "cli_args": [
                  "--log", "debug"
                ],
                "port": 4444
            },
            "desiredCapabilities": {
                "browserName" : "firefox",
                "acceptInsecureCerts": true
            }
        }
    }
}

Either solution works equally well, but the nightwatch.conf.js is probably more future proof and less hassle. If geckodriver or chromedriver change their structure, you don’t have to manually inspect for the .exe which is not in node_modules/.bin/, where it is supposed to be.

Hopefully, this gives some insight and helps some others.

P.S: I also want to note that I was having the same problem with Firefox, as well. This is what necessitated the generic function

Hello All!

I was able to solve this issue just now by doing the following:

// nightwatch.conf.js (not using a json file for config either)
const chrome = require('chromedriver')

module.exports = {
  src_folders: ['tests'],
  webdriver: {
    start_process: true,
    server_path: chrome.path,
    port: 9515,
  },
  test_settings: {
    default: {
      desiredCapabilities: {
        browserName: 'chrome',
      },
    },
  },
}

This now exits properly on completion on Windows.

P.S: I also want to note that I was having the same problem with Firefox, as well. This is what necessitated the generic function

This solved my problem “server_path”: “node_modules/chromedriver/lib/chromedriver/chromedriver.exe” insted of ‘server_path’: ‘node_modules/.bin/chromedriver’,

I resolved this by downloading the chromedriver files manually from here and adjusting the path inside nightwatch.json instead of node_modules/.bin/chromedriver to node_modules/.bin/chromedriver.exe. I use Windows machine and I believe the problem is that npm install command missed to install .exe file for me.