« Design flaw? | Main | Bug tracking with Subversion? »

Virtual framebuffers, FireFox, Selenium and ImageMagick

Some time soon I hope to setup selenium running on our dev server as an additional means of testing our applications that have instances on there. The dev server is headless (no X server) so there's a copy of FireFox 1.0.7 and a virtual framebuffer (Xvfb) which I hope to use instead. I haven't gotten that far yet but I did try a test yesterday using ImageMagick - I wrote a little bash script (shudder) to capture the front page of every instance of an application running on the server and present them as thumbnails in a HTML page. It works a treat! Let's hope I can get Selenium working as easily.

The core commands required if you want to try this on your own server are:

> Xvfb :1 -screen 0 1024x768x24 &
> DISPLAY=:1 firefox http://whatever.url.you/want/to/see &
> DISPLAY=:1 import -window root captured.png
> convert captured.png -resize 256 resized.png
> killall firefox
> killall Xvfb

The import and convert commands are part of ImageMagick. The resize will determine the vertical dimension automatically if omitted. It's a pretty dumb sequence of commands but you get the point.

I got the information I needed from this page on the semicomplete blog by Jordan Sissel.

Comments

Update: I realised while my script works fine, it doesn't work fine from a cron job because then it fails to start the virtual frame buffer... still trying to work out how to solve this.

Any X experts out there reading this?

Okay, I solved it. Nothing to do with X, just that I forgot that the cron environment is very minimal and so doesn't know the path to Xvfb.

Hey cool!

I haven't had a chance to do anything with Selenium yet, but hopefully soon.

Lots of websites offer "page screenshot" services for crazy money. Rediculuos when it's so easy to do with Xvfb, Firefox, and a little bit of scripting.

If I ever get around to installing vmware, I'm going to try this with IE also in Xvfb.

That is: Xvfb, run vmware, have IE view a page. Do the same for Opera, and you can screencapture test any site in Firefox, IE, and Opera, under Linux, Windows, or Solaris.

Thanks for the link, btw :)

I think the smart part of running a browser capture website isn't the image capture or virtual machine part but about how you queue requests to make efficient use of the virtual machines (e.g. group windows firefox requests together instead of keep start/stopping based on the order of requests), handling security popup dialogs, scrolling the browser window to capture an entire page, handling sites that require login, etc. On that note I used Watir very successfully to drive Internet Explorer and they are developing FireWatir.

I agree.

My original intent for this kind of setup was for unit-testing code for pages. Testing pages in general is entirely possible, and should be explored. It seems like more people are hopping on this bandwagon than I expected, which is quite exciting.

Hopefully someone with more energy than I will come up with some unique service to test drive websites at command. Screenshots are useful, usage animations are more useful. The real benefit comes as you expand into fuller testing of a webpage in general.

Security and other issues are certainly good issues to consider. I'm eager to see what comes of this automagic.

Post a comment