Taking Fullscreen Screenshots with Webdriver and in Internet Explorer too

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:

selenium.captureEntirePageScreenshot(“/users/[username]/[folder/screenshot.png”,””);

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.

-@Before
-public void setUp() throws Exception {
-//driver = new FirefoxDriver();

-WebDriver driver = new InternetExplorerDriver();
-driver.get(“http://www.nydailynews.com”);
-driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
-File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
-FileUtils.copyFile(scrFile, new File(“C://[folder]//[somesubfolder]//nameofmybeautifulscreenshot.png”));

This script opens up a very long page and takes a screenshot in IE.

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.

Happy Testing.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: