代码之家  ›  专栏  ›  技术社区  ›  Sachin Sarola

尝试启动ChromeDriver时出错:无法解析路径:“/node_modules/.bin/ChromeDriver”

  •  0
  • Sachin Sarola  · 技术社区  · 5 年前

    当我设置初始设置Nightwatchjs(使用初学者教程)时,我遇到了这样的错误:

    尝试启动ChromeDriver时出错:无法解析路径:“/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"
      }
    }
    

    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"
          }
        }
      }
    }
    

    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");
        }
    }
    
    1 回复  |  直到 5 年前
        1
  •  7
  •   Sachin Sarola    5 年前

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

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

    enter image description here

    我只需要更改我的文件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"
          }
        }
      }
    }