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 eviltester.com.

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.

      <dependency>
          <groupId>com.github.detro.ghostdriver</groupId>
          <artifactId>phantomjsdriver</artifactId>
          <version>1.0.3</version>
      </dependency>

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"), 
            "tools/phantomjs-1.9.1-windows/phantomjs.exe");

Then I create the driver pointing to the executable:

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);
    caps.setCapability("phantomjs.binary.path", 
                PHANTOMJS_EXE.getAbsolutePath());

    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("phantomjs.page.settings.userAgent", 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.

 

This entry was posted in Selenium Simplified Blog, WebDriver. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *