守夜人 - 使用chromedriver

chr*_*lah 12 selenium-chromedriver nightwatch.js

所以,我看到了堆一个类似的问题在这里,但它没有一个公认的答案,也没有向我提供我所需要的信息..

我正在尝试使用'chromedriver',因为'selenium-webdriver'需要FF版本<= 28.

到目前为止我做了什么.

  • nightwatch.js测试在FF运行良好
  • 下载了chromedriver(npm install chromedriver -g),也npm install chromedriver进入了我的nightwatch项目目录
  • 去了nightwatch/bin/nightwatch.json并编辑了以下代码

     "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/usr/local/bin/chromedriver", <= added this - is this the binary?
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : ""
    }},
    
    Run Code Online (Sandbox Code Playgroud)

还试图更新selenium的设置,使其具有start_process = true和server_path

 "selenium" : {
    "start_process" : true,
    "server_path" : "../selenium-server-standalone-2.39.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/usr/local/bin/chromedriver",
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : ""
    }
  },
Run Code Online (Sandbox Code Playgroud)

不确定我是否指向正确的chromedriver文件/文件夹

还编辑了测试设置

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_host" : "127.0.0.1",
      "selenium_port" : 4444,
      "silent" : true,
      "disable_colors": false,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities" : {
        "browserName" : "chrome",   <= changed this from ff to chrome
        "javascriptEnabled" : true,
        "acceptSslCerts" : true
      }
    },
Run Code Online (Sandbox Code Playgroud)

如果我去运行测试(没有a -e <browser>),例如nightwatch -g <group>,它在FF中启动并运行..

如果我尝试指定chrome浏览器(-e chrome),nightwatch -g <group> -e chrome我会收到以下错误

ERROR There was an error while starting the test runner:


Error: Invalid testing environment specified: chrome
    at Object.CliRunner.parseTestSettings (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:354:15)
    at Object.CliRunner.init (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:31:8)
    at module.exports.runner.runner (/usr/local/lib/node_modules/nightwatch/lib/index.js:512:19)
    at /usr/local/lib/node_modules/nightwatch/bin/runner.js:9:16
    at module.exports.cli.cli (/usr/local/lib/node_modules/nightwatch/lib/index.js:504:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/nightwatch/bin/runner.js:8:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 我如何指向二进制文件(不确定它是什么)

  2. 我在nightwatch.js中的设置是否正确?如果我更改了test_settings的"browserName = Chrome",它如何在FF中运行?

  3. 我错过了什么吗?

提前致谢

小智 6

首先你说

我正在尝试使用'chromedriver',因为'selenium-webdriver'需要FF版本<= 28.

因为你正在使用selenium-server-standalone-2.39.0.jar(旧jar)请从这里下载新的selenium-server-standalone-2.45.0.jar 第二次从这里下载chrome驱动程序Chromedriver基于你的环境

第三次用下面的代码更新你的nightwatch.json

{
"src_folders": [
    "tests"
],
"selenium": {
    "start_process": false,
    "server_path": "bin/selenium-server-standalone-2.45.0.jar",
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
        "webdriver.chrome.driver": "bin/chromedriver",
        "webdriver.ie.driver": ""
    }
},
"test_settings": {
    "default": {
        "launch_url": "http://127.0.0.1/",
        "selenium_port": 4444,
        "selenium_host": "localhost",
        "silent": true,
        "screenshots": {
            "enabled": false,
            "path": ""
        },
        "desiredCapabilities": {
            "browserName": "firefox",
            "javascriptEnabled": true,
            "acceptSslCerts": true
        }
    },
    "chrome": {
        "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

第四个用nightwatch -g -e chrome运行你的组

希望它能解决你的问题.


chr*_*lah 2

确保在项目的根目录中创建一个新的 nightwatch.json 文件。

我犯的错误是尝试使用从http://nightwatchjs.org/下载的包附带的 nightwatch.json 文件,该文件位于nightwatch-0.6.11/bin/nightwatch.json