在本地Docker镜像上运行简单的夜班测试文件时遇到问题。我想弄清楚为什么selenium不想运行本地测试。如果有人认为这一点,任何帮助将不胜感激。谢谢!
这是我的测试文件:
NW-example.test.js
module.exports = {
'End-to-end all browsers' : function (browser) {
browser
.init('http://localhost:3000/')
.setValue('#loginForm-username', '')
.setValue('#loginForm-password', '')
.pause(2000)
.click('#loginForm-submit')
.perform(function(done){
console.log('Done testing')
done()
})
.pause(3000)
.assert.containsText('#app','Welcome,');
}
};
这是我的nightwatch.json文件:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./usr/local/bin/chromedriver",
"webdriver.gecko.driver" : "./usr/local/bin/geckodriver",
"webdriver.edge.driver" : "",
"webdriver.safari.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost:3000",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName" : "chrome",
"javascriptEnabled" : true,
"marionette" : true,
"acceptSslCerts" : true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["headless", "--no-sandbox"]
}
}
},
"firefox" : {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
},
"safari" : {
"desiredCapabilities": {
"browserName": "safari",
"javascriptEnabled": true
}
}
}
}
我得到的错误:
root@2b755e5a6174:/vital-webapp/src/__tests__# nightwatch nw-example.test.js
[Nw Example Test] Test Suite
================================
Running: End-to-end all browsers
20:13:49.642 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@2465e6e1
20:13:49.643 INFO - /session: Executing POST on /session (handler: BeginSession)
20:13:49.646 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test}
20:13:49.646 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 4516
Only local connections are allowed.
20:13:59.737 WARN - timeout
java.net.SocketTimeoutException: timeout
答案 0 :(得分:1)
错误说明了一切:
LDAP
配置 ChromeDriver 时,您已提供以下 desiredCapabilities :
20:13:49.646 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test}
20:13:49.646 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 4516
Only local connections are allowed.
20:13:59.737 WARN - timeout
java.net.SocketTimeoutException: timeout
ChromeDriver 没有" marionette" 的功能,设置为 true 。
删除功能 " marionette" :true 并执行 "desiredCapabilities": {
"browserName" : "chrome",
"javascriptEnabled" : true,
"marionette" : true,
"acceptSslCerts" : true
}