Kat*_*tie 6 chai nightwatch.js
我正在使用Nightwatch JS v0.9.16在我的localhost上运行selenium/chai测试.所有的断言都适用于守夜人,但我无法在报道中看到这个断言.
这个问题已经在这里讨论了:https://github.com/nightwatchjs/nightwatch/issues/601然而它已经关闭但没有解决方案......任何人都可以让它工作吗?
这是我的测试:
var assert = require('chai').assert;
module.exports = {
'pressing the "Servers" tab should change the URL to #servers' : function (client) {
const pages = client.page,
home_page = pages.home(),
servers_page = pages.servers();
home_page.navigate();
servers_page.expect.element('body').to.be.present.before(1000);
client.pause(1000);
servers_page.click('@nav');
servers_page.expect.element('@servers_div').to.be.present.before(1000);
client.url(function(response){
var currentUrl = response.value.replace(client.launch_url,"");
console.log("url is ",response.value);
//***CHAI ASSERTION doesn't get shown on reporter:***
assert(currentUrl.indexOf('#servers')!=-1);
client.end();
});
}
};
Run Code Online (Sandbox Code Playgroud)
此测试通过时的屏幕截图显示除chai之外的所有断言:
当它失败时它显示AssertionError: Unspecified AssertionError:
这是我的测试设置(nightwatch.json)
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "./config/pages/",
"globals_path" : "./config/globals.js",
"selenium" : {
"start_process" : false,
"server_path" : "./libs/selenium-server-standalone-2-53-1.jar",
"log_path" : "./logs/",
"port" : 4444
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost:8081",
"selenium_port" : 9515,
"selenium_host" : "localhost",
"default_path_prefix" : "",
"screenshots" : {
"enabled" : true,
"path" : "./screens/",
"on_failure": true
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["--no-sandbox"]
},
"acceptSslCerts": true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
版本:
"selenium-webdriver": "^3.0.1",
"nightwatch": "^0.9.8",
"chromedriver": "^2.25.2",
"chai": "latest"
Run Code Online (Sandbox Code Playgroud)
根据文档,assert()将消息作为第二个参数(http://www.chaijs.com/api/assert/),你尝试过吗?如果是,是否显示该消息?
或者,您是否尝试过更简单的测试(一个失败,一个失败),例如:assert.isOk(false)& assert.isOk(true)?
client.url()最后,您是否尝试在 的回调之外运行您的 chai 断言?
我不熟悉夜巡,但这就是我会尝试的。