CasperJS – fail test with custom testcase-name in xml report

It took some time, but my PR to CasperJS has landed. Now you can fail a test with a custom value for a testcase node’s name property like:'A custom message', {name: 'custom name'});


When using the --xunit=/path/to/report.xml casperjs is using the message as property for the name of the testcase node in xml report. This means if you fail a test like:'A really long and expressive message');

the resulting xml would look something like:

<testcase classname="a-custom-test-case-name" name="A really long and expressive message" time="0.023">
  <failure type="fail">A really long and expressive message</failure>

Imagine you want to capture and provide an stacktrace from a jsp page as message..

Here comes the optional argument FTW. As stated above, pass in a arbitrary object with a name property like:

var stacktrace = casper.fictional_method_to_capture_stacktrace();, {name: 'stacktrace'});

and you’ll get

<testcase classname="a-custom-test-case-name" name="stacktrace" time="0.023">
  <failure type="fail">Exception in thread "main" java.lang.NullPointerException
    at Test.test(
    at Test.main(

Much better..

This entry was posted in javascript and tagged , . Bookmark the permalink.

One Response to CasperJS – fail test with custom testcase-name in xml report

  1. shoes with lifts says:

    Very interesting points you have observed, thanks for putting up.

Leave a Reply to shoes with lifts Cancel reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>