Using captureEntirePageScreenshot with Selenium
Selenium provides a way to to capture the entire page displayed in the browser as a screenshot and save it as a png file on the disk. This functionality is only available in Selenium RC and is available for firefox (*chrome mode) and in IE (*iexploreproxy ) using Experimental utility Snapsie.
// Capture screen shot selenium.captureEntirePageScreenShot("screenshot.png");
Firefox is supported out of the box but it needs little setup for it to work in IE. To use the method in IE go through following steps.
1. Download and install Microsoft VC++ Redistributable Package
2. Download and unzip Snapsie from http://snapsie.sourceforge.net/
Copy Snapsie.dll to windows/system or windows/system32 folder Register Snapsie.dll using “regsvr32 Snapsie.dll
3. Snapsie download comes with some tests, open the test files and try to save the page in browser as a screenshot. You will have to allow the browser to install the active-x control since snapsie is an active-x control.
4. Add the site you are testing and want to capture to Trusted Sites in Internet Explorer otherwise the active-x control will not be loaded when you run your site through RC and try to capture the screenshot.
To programatically add your site to Trusted Sites for Internet Explorer add the following keys to windows registry. Save the contents in .reg file and double click to run or call from a windows batch script. The following example adds http://www.aol.com to the trusted sites.
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains] @="" [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\aol.com] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\aol.com\www] "http"=dword:00000002
If you run your tests on a fresh windows image every time, here is a sample .bat file you can use to install all the above things and start your selenium tests.
@echo off REM Install in silent mode C:\selenium-tests\vcredist_x86.exe /Q C:\windows\regedit.exe /s C:\selenium-tests\ie-trusted-sites.reg copy C:\selenium-tests\snapsie-0.2\Snapsie.dll C:\windows\system32\Snapsie.dll C:\windows\system32\regsvr32.exe /s C:\windows\system32\Snapsie.dll REM Start your tests here