Skip to main content

Aug 30, 2013 - 2 minute read - Selenium Simplified Blog WebDriver

Alternative Uses for GhostDriver and Headless Browser testing

I’ve been using GhostDriver recently.

I could never get along with HTTPUnit driver, it so rarely worked for me. But GhostDriver has been magnificent.

Whenever I want to do any headless browser testing I use GhostDriver.

I blogged about my use of GhostDriver to test www to mobile site redirection, over on

I’ve also been using it as part of a “Tester’s Link Checker” I’ve been experimenting with.

I use it because it is easy to add to my project.


And I just make sure I download the PhantomJS executable as well. I’ve been adding it into a tools sub folder of my project that I don’t check in to version control.

    public static final File PHANTOMJS_EXE =
            new File(System.getProperty("user.dir"), 

Then I create the driver pointing to the executable:

    DesiredCapabilities caps = new DesiredCapabilities();

    PhantomJSDriver driver = new PhantomJSDriver(caps);

PhantomJS and GhostDriver have been working flawlessly for me.

What I love about it, is that it is so easy to change the user-agent

caps.setCapability("", agent);

Coupled with the WebDriver ability to set browser sizes:

driver.manage().window().setSize(new Dimension(320, 480));

I’ve been happily crawling web sites with different user-agents and setting the screen size to the correct size so I can harvest a bunch of screenshots which show me an approximation of the responsiveness of the site’s HTML.

The link checker code isn’t ready for release, but if you want a simple example of how I’ve been using GhostDriver to test mobile site redirection by controlling the user-agent then you could head off to github and see the code.


You will need a Github account to comment. Or you can contact me with your comment.

I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, etc.