2014-09-01 51 views
0

执行脚本时,它将永远不会到达“我永远不会执行”的行。CasperJS(SlimerJS引擎),在评估后步骤不会继续

/*********/

var casper = require('casper').create(
{ 
    //clientScripts: ["includes/jquery-1.11.1.min.js"], 
    waitTimeout: 15000, 
    stepTimeout: 5500, 
    verbose: true, 
    logLevel: 'debug', 
    viewportSize: { 
     width: 1680, 
     height: 1050 
    }, 
    onRunComplete: function() { 
    // Don't exit on complete. 
    }, 
    onWaitTimeout: function() { 
     logConsole('Wait TimeOut Occured'); 
     this.capture('xWait_timeout.png'); 
     this.exit(); 
    }, 
    pageSettings: { 
     "ignoreSslErrors": true 
    }, 
    onStepTimeout: function (self, m) { 

    } 
} 
); 

var subjectParameter = casper.cli.get("subject"); 
var timeoutForScreenshot = casper.cli.get("timeoutForScreenshot"); 
casper.options.stepTimeout = timeoutForScreenshot + 500; 

casper.on('step.timeout', function (request) { 
    console.log("---------------STEP:timed out---------------------:" + request); 
    request.abort(); 
}); 

casper.start('https://email.t-online.de', function() { 

    casper.userAgent('Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko)'); 

    casper.waitForSelector('input[name=pw_usr]', function() { 

     this.fillSelectors('form[name="login"]', { 
      'input[name=pw_usr]': '[email protected]', 
      'input[name=pw_pwd]': 'somePassword' 
     }); 

    }, function() { 
     casper.log('no login-form found', 'error'); 
     casper.exit(); 
    }); 

    casper.then(function() { 
     this.click("#pw_submit"); 
    }); 

    casper.waitForSelector('#rowListContainerTable', function() { 
     //abort.request(); 

     this.evaluate(function getElementInDom(term) { 

      var els = document.getElementsByTagName('span'); 
      var len = els.length; 

      for (var i = 0; i < len; i++) { 
       if (els[i].innerHTML.indexOf(term) != -1) { 
        els[i].click(); 
        abort.request(); 
       } 
      } 

     }, subjectParameter); 

     this.then(function() { 
      this.echo("I WILL NEVER BE EXECUTED"); 
     }); 

     this.wait(8000, function() { 
      this.capture('tonline - ' + subjectParameter + '.png', { 
       top: 0, 
       left: 0, 
       width: 1680, 
       height: 1050 
      }); 

      casper.log('mail found', 'error'); 
      //casper.exit(); 
     }); 

    }, function() { 
     casper.log('login failed', 'error'); 
     casper.exit(); 
    }); 

}); 

casper.run(); 

“subjectParameter” 是一个字符串

“timeoutForScreenshot” 是一个int值

脚本被登录到“https://email.t-online.de”,并寻找一个电子邮件的主题==“subjectParameter”,它打开邮件,并应该截图,但之后,“getElementInDom-Step”之后的所有其他“步骤”将不会执行。

有没有办法在step.timeout之后继续下一步“step”?

+0

如果'abort'不是页面上下文中的全局属性,并且for循环不会进一步执行,'abort.request();'将产生错误。另请参阅[这里](http://stackoverflow.com/q/15739263/1816580)如何点击页面上下文中的元素。这不应该是slimerjs的问题。 – 2014-09-02 07:40:37

回答

0

答: 忽略一个特定的请求URL(从googleadservices)这样的:

casper.on('resource.requested', function (requestData, request) { 
    if (requestData.url.indexOf('xplosion') != -1) { 
     request.abort(); 
    } 

}); 

和它的工作!