Painful Selenium Testing – Part 4 – Firefox Screenshot

Facebooktwittergoogle_plusredditpinterestlinkedinmail

One problem with selenium (using either IDE, RC or Webdriver) is that you don't know what actually happened during the execution.

The selenium result would give some hints, e.g. if the verifyTextPresent failed then you know there is a missing text during execution. But you would like to know what actually appears on that screen? Did the page show up an error page? Or just the value is changed, or probably the server died?

The nature of automated testing is that you are unlikely to watch the executions all the time. Otherwise it's pointless to do the automation.

My first approach is to use camstudio to do screen recording every night, so if there are some problems we could just check back the videos. But there are two major problems:

  1. the video is quite long, it took a lot of time to find out what's going on in that particular moment.

  2. during the execution, the browser size is actually halved (the other half is for the selenium runner), so you are unlikely to see the full screen during the run. This problem is even worse when you try to execute multiple testings in parallel.

So later, I switched to the second approach - use screen capture of firefox. I found that the selenium does support some sort of screenCapture internally. What I need to do is just extract and trigger the particular code snippet.

Source Code

Due to the architecture of Selenium, the source code of firefox screen capture could be found in two possible places:

  1. the source repository of selenium

  2. extract the source code from selenium IDE plugin

    • download the Selenium IDE plugin from firefox
    • check the downloaded plugin folder
    • unzip the plugin

For simplicity, I just collected the source code from the repository. After the source code is found, you only need to do:

grep -ir screenCaputre *

Then you would see the corresponding part of screenCapture. You could copy the corresponding code to the user-extensions.js, and you would be able to use it.

However, trying to trigger it during the error is another story. You are going to change the following four functions. Two for Selenium IDE, and two for Selenium Server.

HtmlRunnerTestLoop.prototype.resume HtmlRunnerTestLoop.prototype.continueTestWhenConditionIsTrue TestLoop.prototype.resume TestLoop.prototype.continueTestWhenConditionIsTrue

In short, you need to add the followings to the end of user-extensions.js. (Sorry for the messy debug messages 🙂 )


One may get the full source code from here:

https://github.com/motherapp/enhanced-selenium-user-extensions

Leave a comment

Leave a Reply

Your email address will not be published.

*