gpt4 book ai didi

javascript - casper.js 退出实例 onStepTimeout

转载 作者:行者123 更新时间:2023-11-28 01:53:57 24 4
gpt4 key购买 nike

嗨,我在 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 timeout: step + 步骤名称,但不会移动到下一个实例或步骤...我想要的是当那个达到 stepTimeout 时,实例应立即 exit() 并移至下一个 thenOpen() 实例...有什么办法吗?

最佳答案

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

关于javascript - casper.js 退出实例 onStepTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19386511/

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