CasperJS - 如何跳到下一个测试套件?

时间:2015-03-29 10:30:14

标签: javascript testing casperjs ui-automation

我引用此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排名第一"上面例子中的测试套件?

或者换句话说,有没有办法跳到下一个可用的casper.test.begin()块?

我已经尝试了test.skip(),并且给定的文档并未提供有关如何实现上述目标的建议。

2 个答案:

答案 0 :(得分:0)

使用CasperJS提供的公共API无法做到这一点。

话虽如此,CasperJS的测试人员模块在queue中管理测试用例。所以你只需致电

test.queue.shift();

删除下一个test.begin()块或

test.queue.splice(1, 1); // second block after the next one
// position ----- ^  ^
// amount of blocks -´

删除任何未来的阻止。请注意,如果测试用例本身不是异步的,这将不起作用。这也是我在概念证明中使用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.

答案 1 :(得分:0)

我使用了以下解决方案:

casper.start(url, function () {
  this.thenBypassIf(my_condition, 1);
});
casper.then(function() {
  // This step will be ignored if the above "my_condition" is true.
});
相关问题