TA basics: Making screenshots when scenarios fail

A picture sometimes says more than words. This is also true for test automation. Therefore it could be that you want your framework to make a screenshot when a scenario is failing to make debugging more easy. But how can you make sure your framework does this for you?


Since we're using the `lapis_lazuli` gem, this is actually already been taken care off for most scenario's, but if you're using the 'watir' gem, you need to modify your `hooks.rb` file like briefly described on this page. Let's first look at Watir and then move to LapisLazuli to see what advantages and disadvantages are between the two.

Watir screenshots

Watir by default does not make a screenshot of a failing test, so you need to write some code to make this work. Below a Watir example
Keep in mind that this only makes a screenshot at the end of the scenario. Meaning that it can happen that the screenshot is being taken a fraction later and thus missing the real issue. So let's take a look at how LL solves this.

LL screenshots

When using LapisLazuli you don't need to put anything in the `hooks.rb`, the only thing that you need to have enabled is `screenshots_height: full` in the `config.yml`. This takes care of what you otherwise manually need to code with Watir, but there is another nifty trick. LL also makes a screenshot right at the moment a `find` or `wait` command fails. So if it can't find the element you need it immediately takes the screenshot. So LL takes away the hassle of coding this and makes sure that the screenshot is taken at the moment the test failed.

The catch

But there is one catch. And that is a rare occasion where a `elm.click` is failing (e.g. when an element is overlapping the one you want to click, like the picture of this blog) and you make use of `browser.refresh` functionality in `hooks.rb` with the current version (v2.1.4) of LL. What happens is that the scenario fails (because a click was not possible), but you first go through the hooks which will refresh the browser. Meaning the screenshot is being taken after the refresh of the browser, so you don't see the actual issue which was so conveniently being captured in a screenshot for you (see this screencapture). This issue is logged on github to track here.

Workaround > Use Watir

Comments

Popular posts from this blog

PowerShell - How to overcome Azure VM's fixed resolution limitation

TA Basics: Website Test Automation on mobile devices via Appium server

TA: Who doesn't like proxies? Me!