gpt4 book ai didi

javascript - 有没有办法控制casper的控制台输出?

转载 作者:行者123 更新时间:2023-11-28 00:44:17 25 4
gpt4 key购买 nike

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

谢谢

最佳答案

由于您正在运行 CasperJS 测试环境,因此可以添加 --concise option当你运行 CasperJS 时:

casperjs test --concise yourTest.js

这会隐藏所有断言日志,但不会隐藏失败的附加信息:

Test file: test20_only_show_fail.js#    type: assert#    file: test20_only_show_fail.js:8#    code: test.assert(false, "false");#    subject: false#    type: assert#    file: test20_only_show_fail.js:13#    code: test.assert(false, "false");#    subject: falseFAIL 3 tests executed in 0.027s, 1 passed, 2 failed, 0 dubious, 0 skipped.

But now you can't distinguish them easily. You can add an event listener to the front of your test file and let it print something useful:

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

这会产生附加信息后面的 FAIL 行:

Test file: test20_only_show_fail.js#    type: assert#    file: test20_only_show_fail.js:7#    code: test.assert(false, "false");#    subject: falseFAIL false#    type: assert#    file: test20_only_show_fail.js:12#    code: test.assert(false, "false");#    subject: falseFAIL falseFAIL 3 tests executed in 0.028s, 1 passed, 2 failed, 0 dubious, 0 skipped.

This is the test file (test20_only_show_fail.js) for reference:

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");
});

关于javascript - 有没有办法控制casper的控制台输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27571727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com