我正在尝试设置Nightwatch,以便我不必使用Selenium而是直接指向Linux上的Chrome实例,但我似乎无法连接到chromedriver实例。
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "globals.js",
"selenium" : {
"start_process" : false,
"cli_args" : {
"webdriver.chrome.driver" : "./chromedriver"
}
},
"test_settings" : {
"default" : {
"selenium_port" : 9515,
"selenium_host" : "127.0.0.1",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"acceptSslCerts": true
}
}
}
}
尝试运行简单的测试套件后,出现以下错误
~/scripts/TestNightwatch$ nightwatch
[Test] Test Suite
=====================
Running: Demo test Google Error processing the server response:
unknown command: wd/hub/session
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started? { value: -1, error:
'Unexpected token u in JSON at position 0' }
我没有正确配置夜视以连接到Chrome吗?我错过了任何拼图吗?
提前致谢!
var chromedriver = require('chromedriver');
module.exports = {
before : function(done) {
chromedriver.start();
done();
},
after : function(done) {
chromedriver.stop();
done();
}
}
答案 0 :(得分:0)
问题可能是Chromedriver期待/
而不是/wd/hub
的命令。要解决此问题,请使用--url-base=/wd/hub
来源:Selenium WebDriverJS, cannot build webdriver for Chrome和https://github.com/webdriverio/webdriverio/issues/113
答案 1 :(得分:0)
您需要在外部全局文件中启动chromedriver。看起来你的配置是正确的。只需在外部全局模块中设置before
和after
函数即可启动chromedriver。
before : function(done) {
chromedriver.start();
done();
},
after : function(done) {
chromedriver.stop();
done();
}
请查看Getting Started指南了解详情。