casper.js退出实例onStepTimeout

时间:2013-10-15 16:40:57

标签: javascript phantomjs casperjs

嗨,我在casper.js中有以下代码

var casper = require('casper').create({
    pageSettings: {loadImages : true,loadPlugins : false}, 
    logLevel :"debug" ,
    verbose : true, 
    onTimeout : function(){ //what to do if timeout reaches?

        this.echo('Failed to load resource.').exit();       
    },
    onStepTimeout: function(){ //what to do if specific step timeout reaches.

        this.echo('timeout: step '+ this.requestUrl);
    }
    });
    //our userAgent


casper.userAgent('Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0');
casper.echo("Will google.com load in less than 2000 ms?");
casper.options.timeout = 2400100; //4 Minutes for process to complete it self.
casper.options.stepTimeout = 24000; //24 seconds for each step to complete it self.
casper.start("http://www.google.com/", function() {
    this.echo("Google done!");
    this.clear();
});
casper.thenOpen("http://www.bing.com/", function() {
    this.echo("Bing done!");
    this.clear();
});

casper.run(function() { 
this.echo('Finished everything!');
this.exit();
});

现在在这段代码中我有stepTimeout到2400ms,但是当达到这个超时时脚本echo'es超时:步骤+步骤名称但不移动到下一个实例或步骤...我想要的是当那个达到stepTimeout,实例应该立即退出()并移动到下一个thenOpen()实例......有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

看看这个https://github.com/n1k0/casperjs/blob/master/samples/steptimeout.js#L17 尝试使用test.fail和test.pass

相关问题