我引用这个example :
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
...
});
casper.test.begin('Casperjs.org is first ranked', 1, function suite(test) {
...
});
在本例中执行第一个测试套件时,如何跳转到测试套件?我想跳转到上面例子中的“Casperjs.org is first ranked”测试套件?
或者换句话说,有没有办法跳到下一个可用的 casper.test.begin()
block ?
我试过了test.skip()
并且给定的文档没有给我关于如何实现上述目标的想法。
最佳答案
这对于 CasperJS 提供的公共(public) API 是不可能的。
话虽如此,CasperJS 的测试器模块在 queue 中管理测试用例。 .所以你可以简单地调用
test.queue.shift();
删除下一个 test.begin()
block 或
test.queue.splice(1, 1); // second block after the next one
// position ----- ^ ^
// amount of blocks -´
删除任何 future 的 block 。请注意,如果测试用例本身不是异步的,这将不起作用。这也是我在概念验证中使用 casper.start().then().run()
组合的原因。
警告:这没有记录在案,可能会在未来的版本中发生变化。
概念验证:
casper.test.begin("test 1", function(test){
casper.start().then(function(){
test.assertTrue(true);
}).run(function(){
test.done();
});
});
casper.test.begin("test 2", function(test){
casper.start().then(function(){
//test.queue.splice(0, 1);
test.queue.shift();
test.assertTrue(true);
}).run(function(){
test.done();
});
});
casper.test.begin("test 3 (invisible)", function(test){
casper.start().then(function(){
test.assertTrue(true);
}).run(function(){
test.done();
});
});
casper.test.begin("test 4 (visible)", function(test){
casper.start().then(function(){
test.assertTrue(true);
}).run(function(){
test.done();
});
});
输出:
Test file: skip_begin_block.js # test 1 PASS test 1 (NaN test) PASS Subject is strictly true # test 2 PASS test 2 (NaN test) PASS Subject is strictly true # test 4 (visible) PASS test 4 (visible) (NaN test) PASS Subject is strictly true PASS 3 tests executed in 0.226s, 3 passed, 0 failed, 0 dubious, 0 skipped.
关于javascript - CasperJS - 如何跳到下一个测试套件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29328029/