Author image

A fully-automated testing rig #6

Part 6: Manually fail a test, but continue script execution

We set up an event to take screenshots of failed test pages, by hooking into the onFail event. This made for a problem when we wanted to pass or fail a test based on whether there were entries in the Drupal Watchdog table. Failing a test also would normally stop script execution, but we explicitly need our post script to finish its work!

CasperJS fortunately allows you both to pass and fail tests manually, and also to create your own events. We created a manual_fail event in our pre script, which we could call from our Watchdog test, to fail the test without causing a screenshot. As the onFail event is called from outside the post script, it can continue execution.

In our pre script we have:

# Create a custom fail event, which allows us to manually fail tests without stopping script execution
  casper.on "manual_fail", (test, text) -> text

Then in our post script, we have the following to fire the event:

# Shout about any failures
    if table.length > 0
      this.emit "manual_fail", test, "#{table.length} Watchdog Logs found"
Next article in series: 
Previous article in series: