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:


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.

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.

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.

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

-WebDriver driver = new InternetExplorerDriver();
-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.


Getting Started with JUnit Reports with Eclipse and Ant…

So a lot of people have been asking me about how to create JUnit Reports with their automated test cases. I’m going to show you how to create these reports in the easiest way possible. You will not have to download anything, add any code, etc. You will only have to use generate the HTML report using Ant with Eclipse.

The first think you have to do is generate the Ant build. You can do this by:

1. Right click on the project and
select Export –> Ant Buildfiles (this will be under General) –> Next–> Select the project that contains your JUnit tests –> Finish.

The default JUnit output directory is appropriately named “junit”.

2. The next thing you have to do is resolve your dependencies by making sure that the junit.jar is added to
Ant’s “Global Entries.”. You can do this by.

Window->Preferences->Ant->Runtime->Global Entries and Add External JARs… Navigate to your “eclipse” directory (where eclipse is installed). It is under “plugins” directory and presently the junit.jar is in a directory named “org.junit_3.8.1”. If this is missing then you will see error messages since
junit is an optional Ant task.

* If you are using a Mac, Preferences are under the the Eclipse menu.

3) Finally, right-click on the Ant build file build.xml (this file is the one you created in Step 1) and Run As->Ant Build. This will display a list of targets. All of the launch configurations you have previously configured will have a corresponding target in your Ant build file. Select the desired target(s), and also select the “junitreport” target (very important). Check the “Target execution order” text area to make sure the junitreport is run last.

As you can see I’ve specified the order in which I want my cases to run (below)

JUnit Targets

Whenever you run a test case it will generate results and will be placed in the junit output directory. These results are formatted into an HTML report by the junitreport target and stored in the junit output directory.

As you can see below my automated Test Suite has completely run and you can see which tests failed and which passed (below). I see my cases for login, registration, and account-sign up are failing. Upon further investigation, these are failing because the web service is down on our staging server.

Pass or Fail

This is a fast and easy explanation of how to create JUnit HTML reports, but hopefully it helps get you off your feet. Next time around, we’ll have some more fun when I show you how to extend this output to get more information displayed in the report. For example to add an additional column which contains link to a screenshot taken by the test.

Happy Testing!