【问题标题】:Prevent CasperJS from exiting when all steps are complete防止 CasperJS 在所有步骤完成后退出
【发布时间】:2016-05-27 20:12:52
【问题描述】:

我有一个动态 CasperJS 套件,它围绕 PhantomJS 中内置的 WebServer 工作。新步骤会动态添加到套件中。

但是,现在,只要完成所有待处理的步骤,Casper 就会存在。

如何防止它自动关闭并等待动态添加更多步骤?

【问题讨论】:

    标签: javascript phantomjs casperjs


    【解决方案1】:

    您可以将onComplete 函数传递给casper.run(),如果onComplete 函数永远不会结束,casper 将不会退出。试试这个代码:

    var casper = require('casper').create({
        verbose: true,
        logLevel: "debug",
    });
    
    casper.start()
    
    casper.then(function () {
        casper.echo("the first step")
    })
    
    casper.then(function () {
        casper.echo("the second step")
    })
    
    casper.then(function () {
        casper.echo("the third step")
    })
    
    casper.run(function () {
        setInterval(function () {
            casper.echo('step: ' + casper.step)
        }, 1000)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2021-10-20
      • 1970-01-01
      相关资源
      最近更新 更多