【发布时间】:2021-07-13 16:34:51
【问题描述】:
我正在使用 Nightwatch JS v0.9.16 在我的本地主机上运行 selenium / chai 测试。所有断言都适用于守夜人,但我无法让 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();
});
}
};
此测试通过时的屏幕截图显示了除 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
}
}
}
}
版本:
"selenium-webdriver": "^3.0.1",
"nightwatch": "^0.9.8",
"chromedriver": "^2.25.2",
"chai": "latest"
【问题讨论】:
-
真的希望有人对此也有解决方案。
标签: chai nightwatch.js