防止 CasperJS 在所有步骤完成后退出
Prevent CasperJS from exiting when all steps are complete
我有一个动态的 CasperJS 套件,它围绕 PhantomJS 中内置的 WebServer 工作。新步骤动态添加到套件中。
但是,现在,只要完成所有未决步骤,Casper 就会存在。
如何防止自动关闭等待更多步骤动态添加?
你可以传递一个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)
})
我有一个动态的 CasperJS 套件,它围绕 PhantomJS 中内置的 WebServer 工作。新步骤动态添加到套件中。
但是,现在,只要完成所有未决步骤,Casper 就会存在。
如何防止自动关闭等待更多步骤动态添加?
你可以传递一个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)
})