【发布时间】:2018-01-18 01:10:05
【问题描述】:
我正在尝试设置 Nightwatch,这样我就不必使用 Selenium,而是直接指向 Linux 上的 Chrome 实例,但我似乎无法连接到 chromedriver 实例。
nightwatch.json
{
"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' }
我是否没有正确配置 nightwatch 以连接到 Chrome?我是否遗漏了任何拼图?
提前致谢!
globals.js
var chromedriver = require('chromedriver');
module.exports = {
before : function(done) {
chromedriver.start();
done();
},
after : function(done) {
chromedriver.stop();
done();
}
}
【问题讨论】:
-
@user8185655 提供的答案似乎解决了我的问题。
标签: selenium-chromedriver nightwatch.js