CasperJS: how to exit script execution?

Yesterday I wrote my first tests with CasperJS, and I find it awesome. The problem is that I could not find a way to exit the script (i.e.: casperjs does not exist, so I can access my console back). I found a workaround by adding a final test, for example:

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

Regarding this technique, I have 2 questions

  • Is there a better way?
  • How will this affect the output to xunit?
+8
phantomjs casperjs
source share
2 answers
 casper.then(function() { this.exit(); }); 

Do you want to exit the script at runtime (due to an error)? If not, then you do not need to explicitly exit it. Just select casper.run () after defining all your tests, and as soon as all the tests are completed (regardless of their result), the script will stop working and you will regain control of your terminal.

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

You can use the run.complete event to wait for all steps to be completed, and then exit.

+3
source share

All Articles