javascript 如何在 CasperJS 中增加超时时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18204305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:04:42  来源:igfitidea点击:

How to increase the timeout in CasperJS

javascriptphantomjscasperjs

提问by user2129794

I am using waitFor(). The code as below:

我正在使用waitFor(). 代码如下:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
    });
}, function then() {
    console.log('Done');
});

Am getting this as console output

我把它作为控制台输出

Wait timeout of 5000ms expired, exiting.

How can I increase the timeout?

如何增加超时时间?

EDIT: I have changed the code to

编辑:我已将代码更改为

 casper.waitFor(function check() {
        return this.evaluate(function() {
            return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
        });
    }, function then() {
        console.log('Done');
    },10000);

It's giving me the following error:

它给了我以下错误:

CasperError: Invalid timeout function, exiting.
    C:/filename:1720 in _check

采纳答案by Cybermaxs

As said here,

正如这里所说,

The signature is

签名是

waitFor(Function testFx[, Function then, Function onTimeout, Number timeout])

So, there is an additionnal argument to specify the timeout.

因此,还有一个额外的参数来指定超时。

casper.waitFor(function check() {
    //...
    });
}, function then() {
     //...
}, function timeout() { 
//...
}, TIMEOUT_IN_MS);

回答by Fanch

Use that to increase the timeout of every wait() functions : casper.options.waitTimeout = 20000; (20sec)

使用它来增加每个 wait() 函数的超时时间:casper.options.waitTimeout = 20000; (20 秒)

回答by warvariuc

If you want to increase timeout while leaving the default error message, pass nullas the third argument and number of milliseconds to wait as the fourth argument:

如果要在保留默认错误消息的同时增加超时,请null作为第三个参数和等待的毫秒数作为第四个参数传递:

casper.waitFor(function check() {
    return this.evaluate(function() {
        return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
    });
}, function then() {
    console.log('Done');
}, null, 10000);