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
I have made a bare minimum repo with instructions that produces the error here: https://github.com/chriswoodle/nightwatch-windows-chromedriver-bug
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)
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!
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.
or we could simply write node_modules/.bin/chromedriver which I believe it will work on all platforms?
@dvalejo Your workaround works great, thanks.
@beatfactor Are you referring to:
{
"webdriver": {
"server_path": "./node_modules/.bin/chromedriver"
}
}
in nightwatch.json?
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
@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.
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.
After experiencing this problem, myself, I came across this Issue. Many thanks to @dvalejo and @chriswoodle, as I found both:
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
@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
@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.
Same issue here.
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.
_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',
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.
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.
run the following commands
then copy the path and put it in your path.
hope this helps.
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"
}
}
}
}
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"
]
}
}
}
}
Most helpful comment
I have the same issue on Windows with http://nightwatchjs.org/gettingstarted. And finaly got this to work with this
nightwatch.conf.js:Just got chromedriver
pathproperty and setwebdriver.server_pathwith that property.