PracticalWeb Ltd

Websites that work for you.

Cross Platform Testing With Selenium and VirtualBox

As well as following standards such as those laid down by I always try and test websites I develop across a range of browsers. Despite improvements in compatibility in recent years, browsers do still vary in implementation and even relatively minor browsers are still used by large numbers of people.

However all this testing can be hard to keep on top of and sometimes I just have to push out what seems like a small code change with only limited testing.

I’m aiming to automate as much testing as possible, this is a little more work up front - but makes re-running tests trivial and so more likely to happen.

I use VirtualBox to run multiple environments, and am happy to find that the newer releases (2.1 and up) support improved networking.

So I have installed Selenium RC on a virtual machine, and by running this simple script I can test on Internet Explorer - from my Linux development machine.


set_include_path(get_include_path() . PATH_SEPARATOR . ‘./PEAR/’); require_once ‘Testing/Selenium.php’;

$selenium = new Testing_Selenium(“*iexplore”, “”, ‘’);


$selenium->open(“/”); $selenium->type(“q”, “hello world”); $selenium->click(“btnG”); $selenium->waitForPageToLoad(10000); print (preg_match(“/Google Search/”, $selenium->getTitle())) ? “pass\n” : “fail\n”; $selenium->stop();


Note that I can specify which Virtual Machine to test on just by providing the appropriate IP address.

This example is in PHP because that’s what I use, it requires the Pear package Testing_Selenium which I installed on Ubuntu by the command

sudo pear install channel://

Now all I need to do is integrate this into my unit testing framework and add some scripts to start up and shut down the virtual machines.

There is also Selenium Grid which is aimed at distributing tests across multiple machines in parallel - but as this is all running on one physical machine (my laptop) I don’t really want parallelisation here.