Failed Tests Are Better With Screenshots

When your test automation is running fine, everything is great with the universe!

Then it happens. A test cases fails and your trace isn’t entirely clear as to where it failed.  Even when the trace is clear, you still have to walk through the test steps to capture a screenshot for the bug. Imagine being able to capture screenshots at the moment of failure.  

Imagine no longer!

Below is a simple condition to end to your teardown def for taking a screenshot at the moment of failure.  

unless passed?
   save_screenshot("images/", "#{method_name}-#{'%Y%m%d-%H%M%S')}.png")

The unless condition will only be triggered when the test fails. The method name (#{method_name}) will be incorporated to the file name. This way you can quickly find the failed test.

Why would you need screenshots when testing?

Screenshots are the best way to capture the error that you would see if you were manually testing. It can show you that elements are out of place, not available on screen, or non-custom error messages with stack traces. It is also something that product owners and engineers alike will look at before your steps to reproduce.

Happy Testing!

Let’s stay in touch!

Photo by Sai Kiran Anagani on Unsplash

One Reply to “Failed Tests Are Better With Screenshots”

Leave a Reply