title: How to get Casper JS to return an exit code that indicates test success status?
body: <p>I want to be able to have a set of Casper JS tests and get an exit code back of 0 on success and non-zero on error or test failure (I want to run the casper command from java and determine if a test passed).</p>
  
  <p>The problem I am having is that an exit code of 0 is always returned. Here is an example test where this happens:</p>
  
  <pre class="lang-js prettyprint-override"><code>var casper = require('casper').create();
  
  casper.start('http://www.google.com', function() {
      this.test.assertEquals(true, casper.cli.options['value']);
  });
  
  casper.run(function() {
          casper.test.done(1);
  });
  </code></pre>
  
  <p>All of the following commands result in an exit code of 0:</p>
  
  <pre><code>C:/casperjs/bin/casperjs test --value=true C:/Temp/simpletest.js
  C:/casperjs/bin/casperjs test --value=false C:/Temp/simpletest.js
  C:/casperjs/bin/casperjs --value=true C:/Temp/simpletest.js
  C:/casperjs/bin/casperjs --value=false C:/Temp/simpletest.js
  </code></pre>
  
  <p>How can I invoke Casper and determine whether the tests succeeded or failed/errored from Java?</p>