夜巡 - 使用 chromedriver

2024-01-26

所以我在堆栈上看到了类似的问题here https://stackoverflow.com/questions/27601103/launch-tests-in-chrome-with-nightwatchjs-on-mac-os-connection-refused-is-sele但它没有得到接受的答案,也没有为我提供我需要的信息。

我正在尝试使用“chromedriver”,因为“selenium-webdriver”需要 FF 版本

到目前为止我做了什么。

  • nightwatch.js 测试在 FF 中运行良好
  • 下载的 chromedriver (npm install chromedriver -g) 并且npm install chromedriver进入我的夜巡项目目录
  • went to 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" : ""
    }},
    

还尝试更新 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" : ""
    }
  },

不确定我是否指向正确的 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
      }
    },

如果我去运行测试(没有-e <browser>) e.g. 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)

我的问题是:

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

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

  3. 我在这里错过了什么吗?

提前致谢


首先你说

我正在尝试使用“chromedriver”,因为“selenium-webdriver” 需要 FF 版本

这是因为您使用的是selenium-server-standalone-2.39.0.jar(旧jar)请从这里下载新的selenium-server-standalone-2.45.0.jar http://www.seleniumhq.org/download/其次从这里下载 chrome 驱动程序Chrome驱动程序 http://chromedriver.storage.googleapis.com/index.html?path=2.15/根据您的环境

第三次使用以下代码更新 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
        }
    }
}

}

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

希望它能解决您的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

夜巡 - 使用 chromedriver 的相关文章

随机推荐