Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting ChromeDriver: cannot resolve path to chromedriver in Windows environment #1992

Closed
chriswoodle opened this issue Jan 18, 2019 · 19 comments
Labels

Comments

@chriswoodle
Copy link

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!

@chriswoodle chriswoodle changed the title ChromeDriver: cannot resolve path in Windows environment Starting ChromeDriver: cannot resolve path to chromedriver in Windows environment Jan 18, 2019
@dmitruk-v
Copy link

dmitruk-v commented Jan 20, 2019

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.

@beatfactor
Copy link
Member

or we could simply write node_modules/.bin/chromedriver which I believe it will work on all platforms?

@chriswoodle
Copy link
Author

@dvalejo Your workaround works great, thanks.

@chriswoodle
Copy link
Author

@beatfactor Are you referring to:

{
    "webdriver": {
        "server_path": "./node_modules/.bin/chromedriver"
    }
}

in nightwatch.json?

@hillriegel
Copy link

I have this issue, too, dvalejo's workaround doesn't work for me... or I don't understand its implementation.

no, './node_modules/.bin/chromedriver' as a path doesn't work... not as a server_path

@chriswoodle
Copy link
Author

chriswoodle commented Jan 25, 2019

@hillriegel For the workaround, you can try the repo I linked in my original post and add the workaround:

All that you should have to do is add a file called nightwatch.conf.js with the content in dvalejo's post, and it should work normally.

@hillriegel
Copy link

thank you, Chris. I did try that originally and it didn't solve my problem. But I"ll try the repo just for kicks. Thanks, again.

@FuzzicalLogic
Copy link

FuzzicalLogic commented Jan 28, 2019

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

@evgeniy-mh
Copy link

@FuzzicalLogic your solution didn't work for me. I get error:
Error: An error occurred while trying to start the Nightwatch Runner: The path to the GeckoDriver binary is not set. Please download GeckoDriver from https://g ithub.com/mozilla/geckodriver/releases, extract the archive and set "webdriver.s erver_path" config option to point to the binary file.

While trying to run npx nightwatch ./tests/hello-world.js

@FuzzicalLogic
Copy link

FuzzicalLogic commented Feb 8, 2019

@evgeniy-mh : To get my solutions, I used the function and uncommented the console.log to get the actual paths that I needed. Then you put them into the nightwatch.json. If the console.log does not get you a path, then the drivers are not installed correctly. You should only need either the conf.js or the .json, but you probably need the conf.js temporarily to get the paths if your preferred method is the .json. YMMV depending on your project setup, but this has worked for all of my nightwatch testing (43 projects since my post) since I figured it out.

@dgateles
Copy link

Same issue here.

@ignasiv
Copy link

ignasiv commented May 7, 2019

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.

@Muscan
Copy link

Muscan commented May 14, 2019

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',

@mattwaler
Copy link

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.

@stale
Copy link

stale bot commented Aug 13, 2019

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

@AliHirsi1
Copy link

run the following commands

  1. npx chromeDriver -v
    the above command will tell you if you have ChromeDriver in your machine but to find out where npx is looking run this command
  2. npx which chromeDriver

then copy the path and put it in your path.

hope this helps.

@promoters98
Copy link

promoters98 commented Aug 10, 2020

Worked for me by changing the server_path in nightwatch.json. Thanks to FuzzicalLogic for his help above.

{
"src_folders" : ["tests"],

"webdriver" : {
"start_process": true,
"server_path": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"port": 9515
},

"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}

@zxmbw54
Copy link

zxmbw54 commented Oct 8, 2020

I have a similar issue with running Nightwatch using Chromedriver but I get the following error message:
An error occurred while trying to start GeckoDriver: cannot resolve path: "node_modules/.bin/chromedriver".
Please check that the "webdriver.server_path" config property is set correctly.

Is there a reason why it shows GeckoDriver instead of ChromeDriver?
This is my nightwatch.json file:

"webdriver" : {
    "start_process": true,
    "server_path": "node_modules/.bin/chromedriver",
    "port": 9515
  },

"test_settings" : {
    "default" : {
      "launch_url" : "https://simplewebrtc.com/demo.html",
      "silent" : true,
      "screenshots" : {
        "enabled" : false,
        "path" : "./screenshots"
      }
    },
  "chrome": {
    "desiredCapabilities": {
      "browserName": "chrome",
      "chromeOptions": {
        "args": [
          "-use-fake-device-for-media-stream",
          "-use-fake-ui-for-media-stream"
        ]
      }
    }
  }  
}

@nikhilbisht
Copy link

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

This works for me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests