All posts tagged Java

Someone had contacted me yesterday about how to take screenshots in Selenium. There are tons of advantages of doing this. First, you can run a job anytime you want, have it visit every page on the website, and review the screenshots for obvious bugs. Second, we can insert screenshots at breaking points, or during any function.

The dreaded problem from what I’ve seen scouring the Internet is how to take screenshots in the Microsoft IE family.

Many have gotten success from using the following code in Firefox and have wondered how to get it work across IE:

First, a lot of things have not worked for me. I’ve tried SnapsIE but I wouldn’t go this route as SnapsIE (The latest snapsie-0.2.) is no longer being actively developed and the last update was in 2008. I tried registering the DLL in IE 9/10 and wasn’t able to get it to work. I can only imagine this would be of no purpose if it only worked in older browsers. Hell, IE8 came out March 19, 2009; so SnapeIE last update was almost a year before. I did not check if this worked for IE8.

captureScreenshot()
This method works in FF an IE but the big problem is that it only takes a screenshot of the content within the screen view. Not too useful if you want the full page.

captureEntirePageScreenshot()
This method does not work either in IE at all; so this is pretty much a useless command for IE screen shots.

Anyway, let’s get to it.
Due to Selenium limitations, you want to user WebDriver to so this because WebDriver makes direct calls to the browser using each browser’s native support for automation. That’s key here. Selenium-RC worked the same way for each supported browser. It ‘injected’ javascript functions into the browser when the browser was loaded and then used its javascript to drive the AUT within the browser. This causes many problems so let’s utilize Webdriver’s powerful capabilities instead.

So, first thing you want to do is download Internet Explorer Driver. The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol. This driver has been tested with IE 6, 7, 8 and 9 on appropriate combinations of XP, Vista and Windows 7. Get the download here. https://code.google.com/p/selenium/downloads/list

Add this exe file to your PATH variable on your Windows machine.

If you need help doing this, please send me an IM.

Once you’ve added this .exe file to your PATH variable, you’re all ready to go.

Try the following code in your test script and Run as a JUnit Test/Ant build, etc.; however you have your scripts set up.

This should work for you in the all the IE browsers that I’ve listed above.

If you’re sick to your stomach of trying this, there’s a pretty cool tool you can find here which will do it manually for you. It works similar to the existing screenshot plug-ins that are available for Chrome and Firefox. But in IE. However, this little manual plug-in did not worked in all the IE’s except in IE 10.