我是 NightWatch 的新手,所以我遵循了几个教程,我做了他们所说的一切,但现在我得到一个标题为“data;”的空白页面,而不是我想看到的页面“https://www.ghandi.com.mx” .
这是 json 文件。看来这个问题是关于json配置的。有什么帮助吗?非常感谢!
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"selenium": {
"start_process": true,
"start_session" : true,
"server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe"
}
},
"test_settings" : {
"default": {
"launch_url": "https://www.gandhi.com.mx/",
"screenshots": {
"enabled": false
},
"desiredCapabilities": {
"browserName": "chrome",
"marionette": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"webdriver": {
"server_path": "C:\\Users\\Esau Alvarez\\Desktop\\NightWatch\\chromedriver.exe"
}
}
}
}
}
这是我的测试文件
module.exports = {
"Test": function (browser) {
browser
.windowMaximize()
.url("https://www.gandhi.com.mx/")
.waitForElementVisible('body', 1000)
}
}
最佳答案
- 在默认部分下,您必须针对 Firefox 进行配置。下载 gecko 驱动程序并在 cli_args 下给出路径。
- 您应该从 Chrome 所需功能中删除服务器路径,正如上面已经提到的那样。两次更改后,您的 nightwatch.json 应该如下所示。
{ "src_folders": ["tests"], "output_folder": "reports", "selenium": { "start_process": true, "start_session": true, "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar", "port": 4444, "cli_args": { "webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe", "webdriver.gecko.driver": "Path to gecko driver.exe" } }, "test_settings": { "default": { "launch_url": "https://www.gandhi.com.mx/", "screenshots": { "enabled": false }, "desiredCapabilities": { "browserName": "firefox", "marionette": true } }, "chrome": { "desiredCapabilities": { "browserName": "chrome" } } } }
Also please increase the wait time to like 2000 or 3000 for the 'body' to be visible, just to be on the safe side.
module.exports = {
"Test": function (browser) {
browser
.windowMaximize()
.url("https://www.gandhi.com.mx/")
.waitForElementVisible('body', 3000)
}
}
因此,根据 nightwatch json,您的默认执行应该在 Firefox 中进行。如果您想在 chrome 上执行相同的操作,您应该使用 chrome 键或将 chrome 配置移至默认部分。
关于javascript - 如何处理获取空白页面而不是 NightWatch 中指定的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603986/