【问题标题】:How to increase the timeout in CasperJS如何增加 CasperJS 中的超时时间
【发布时间】:2013-08-13 08:35:10
【问题描述】:

我正在使用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');
});

我把它作为控制台输出

Wait timeout of 5000ms expired, exiting.

如何增加超时时间?

编辑:我已将代码更改为

 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);

它给了我以下错误:

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

【问题讨论】:

    标签: javascript phantomjs casperjs


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    正如here所说,

    签名是

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

    所以,有一个额外的参数来指定超时。

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

    【讨论】:

    • 您还可以设置一个选项来增加超时。这将是所有定时功能的默认设置。请参阅以下链接:link
    • 请参阅编辑。我已经更新了代码,但收到了编辑中显示的错误
    • 是的,其实第三个参数是onTimeout回调。超时值是第四个。
    【解决方案3】:

    如果您想在保留默认错误消息的同时增加超时,请将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);
    

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      相关资源
      最近更新 更多