CasperJS skip step on timeout

后端 未结 2 1772
礼貌的吻别
礼貌的吻别 2020-12-06 15:36

I have one page in my casperjs test that has images , I dont what to wait until this page loaded to go to the next step. How can I do it ? I have tryed this way

<         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 16:16

    Indeed, in some cases a CasperJS's step can occasionally expire by timeout (if stepTimeout is specified in the settings) due to problems with connection. Default behaviour is to stop CasperJS by this.die. If it's required to not stop CasperJS, but rather continue executing next steps, one should provide a custom onStepTimeout. Unfortunately, request.abort is not defined in this context, because request is only accessible inside onResourceRequested handler (this is why the answer of @Topher Ellis is questionable). In other words, request.abort is useful to prevent a new request from being issued, but can not stop a request which is already in progress (and can be potentially timed out). For such situations I'm using the following code:

    var casper = require("casper").create(
    {
      ...
      onStepTimeout: function(timeout, step)
      {
        this.echo('step timeout');
        this.clear();
        this.page.stop();
      }
    });
    

    Hope this helps.

提交回复
热议问题