An error occurred while trying to start ChromeDriver: cannot resolve path: "/node_modules/.bin/chromedriver"

Sac*_*ola 4 selenium nightwatch.js e2e-testing

When I am setting the initial setup Nightwatchjs(using the beginner tutorial) I got the error like:

An error occurred while trying to start ChromeDriver: cannot resolve path: "/node_modules/.bin/chromedriver".

package.json

{
  "name": "intro-to-nightwatchjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "nightwatch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "chromedriver": "^80.0.1",
    "minimist": "^1.2.5",
    "nightwatch": "^1.3.4",
    "optimist": "^0.6.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

nightwatch.conf.js

module.exports = {
  "src_folders" : ["tests"],

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

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

firstTest.js

module.exports = {
    'My first test case'(browser){
        browser
            .url("https://www.bla-bla.com/")
            .waitForElementVisible('.bla-bla-class')
            .assert.containsText(".bla-bla-class", "bla bla text");
    }
}
Run Code Online (Sandbox Code Playgroud)

Sac*_*ola 7

最后,当我向他展示教程的 git 帐户并发布解决方案时,我得到了一个解决方案。

https://github.com/coding-with-dom/intro-to-nightwatchjs/commit/a2e0e05351c9e1c9e108bdf1083ae2a03e0296d1

在此输入图像描述

我只需要更改我的文件 nightwatch.conf.js

module.exports = {
  "src_folders" : ["tests"],

  "webdriver" : {
    "start_process": true,
    "server_path": require('chromedriver').path,
    "port": 9515
  },

  "test_settings" : {
    "default" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)