有没有办法控制卡斯珀的控制台输出

Is there a way to control casper's console output?

本文关键字:控制台 输出 卡斯 控制卡 控制 有没有      更新时间:2023-09-26

只是想知道是否可以强制 casperjs 只将失败的测试输出到控制台。有没有人尝试过这样做?

谢谢

由于您运行的是 CasperJS 测试环境,因此您可以在运行 CasperJS 时添加 --concise 选项:

casperjs test --concise yourTest.js

这将隐藏所有断言日志,但不会隐藏 FAIL 的其他信息:

测试文件:test20_only_show_fail.js# 类型:断言# 文件: test20_only_show_fail.js:8# 代码: test.assert(false, "false"(;# 主题:假# 类型:断言# 文件: test20_only_show_fail.js:13# 代码: test.assert(false, "false"(;# 主题:假失败 在 0.027 秒内执行 3 次测试,1 次通过,2 次失败,0 次可疑,0 次跳过。

但是现在你不能轻易区分它们。您可以将事件侦听器添加到测试文件的前面,并让它打印一些有用的内容:

casper.test.on("fail", function(failure) {
    this.casper.echo("FAIL " + failure.message);
});

这将生成附加信息后面的 FAIL 行:

测试文件:test20_only_show_fail.js# 类型:断言# 文件: test20_only_show_fail.js:7# 代码: test.assert(false, "false"(;# 主题:假失败假# 类型:断言# 文件: test20_only_show_fail.js:12# 代码: test.assert(false, "false"(;# 主题:假失败假FAIL 在 0.028 秒内执行 3 次测试,1 次通过,2 次失败,0 次可疑,0 次跳过。

这是供参考的测试文件 (test20_only_show_fail.js(:

casper.test.on("fail", function(failure) {
    this.casper.echo("FAIL " + failure.message);
});
casper.test.begin('fail test', function(test) {
    test.assert(true, "true");
    test.assert(false, "false");
    test.assert(true, "true (2)");
});
casper.test.begin('error test', function(test) {
    test.assert(false, "false");
});