CasperJS: how to exit script execution?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 07:59:07

问题


Yesterday I've written my first tests with CasperJS and I find it amazing. The problem is that I couldn't find a way to exit the script execution (ie: casperjs doesn't exist so I can get back access to my console). I've found an workaround by adding a final test like so

casper.test.begin('Exit', function suite(test) {
    casper.exit();
});

Regarding this technique I have 2 questions

  1. Is there a better way?
  2. How would that impact the output of the results to xunit file?

回答1:


casper.then(function() {
    this.exit();
});

Do you want to exit the script while it's running (due to an error)? If not, then you don't need to explicitly exit it like that. Just call casper.run() after defining all your tests, and once all the tests have run (regardless of their result), the script will stop running and you'll regain control over your terminal.




回答2:


casper.on('run.complete', function() {
        this.echo('Test completed');
        this.exit();
});

You can use the run.complete event to wait till all steps are executed and then exit.



来源:https://stackoverflow.com/questions/18482357/casperjs-how-to-exit-script-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!