Skip to main content

A fully-automated testing rig #6

An article from ComputerMinds - Building with Drupal in the UK since 2005
29th Jul 2014

Nathan Page

Developer
Nathan Page
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

##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) -> 
      casper.test.fail 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"

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.