Watir-WebDriver with GhostDriver on OSX: headless browser testing

GhostDriver has been released which means it is now easy to run reliable headless WebDriver tests on Mac OSX.

Steps to get working on OSX

  1. First make sure you have homebrew installed
  2. Run
    brew update

    then

    brew install phantomjs

    which should install PhantomJS 1.8.1 or newer

  3. Run irb and start using GhostDriver!
    require 'watir-webdriver'
    b = Watir::Browser.new :phantomjs
    b.goto "www.google.com"
    b.url #"http://www.google.com.au/"
    b.title #"Google"

I’ve tested it on a large test suite (123 scenarios) and it behaves the same as other browsers with full JavaScript support. It took 8m13s in total: surprisingly it is slightly slower than ChromeDriver (7m30s) in my testing, but a little faster than the Firefox Driver (9m33s).

Well done to all involved in this project. It’s great to see a reliable, realistic headless browser with full JavaScript support for WebDriver finally released.

And yes, in case you’re wondering, it does screenshots!

14 thoughts on “Watir-WebDriver with GhostDriver on OSX: headless browser testing

  1. I am excited to see a headless option finally become available WebDriver family. I am however puzzled… I thought the whole point of having a headless browser was that it was supposed sooooo much faster than a real browser ? Has anyone ever really put together comprehensive metrics on headless vs real browsers ? I’d be curious to know the truth.

    Great Blog! BTW I’ve learned a tremendous amount between yourself and Cheezy keep up the great work! and Thanks!

    1. You’re probably thinking of headless browsers without JavaScript support, which aren’t much use for modern web apps that won’t work unless you have JavaScript enabled.

  2. This is fantastic news! Thanks.

    Only problem I have is the site I’m trying to use it with doesn’t like the agent string PhantomJS is providing. Aside from building my own PhantomJS binary, is there a way to set this with Ruby-Watir-Webdriver-PhantomJS?

  3. …headless browsers are good to some extent but do not suffice 100% automation needs. There are still scenarios where we need to make sure a page is rendered fine on multiple versions of a browser and platforms. Headless can be used in areas where you are clearly sure about your browser version used by the customer/end-user.

  4. Thanks, Alister, it worked great on CentOS 6.3. One caveat is that the latest selenium-webdriver (2.29.0) must be installed. (I didn’t think about this.)
    About performance, wouldn’t phantomjs to take much less resources than starting up a new instance of browser. I’m starting to use minitest parallel feature and could bring up many instances of browser and run parallel tests. But this seems to be a memory hog.

  5. This is really great! PhantomJS works beautifully, however, I can’t for the life of me figure out how to pass arguments to it. I’ve tried:
    switches = “–proxy=x.x.x.x:8800″
    @b = Watir::Browser.new(:phantomjs,:switches => switches)

    Any ideas on how to do this?

  6. I am using watir with rspec in my recent project and facing a weird issue with phantomjs. It launches headless browser but all tests are failing as it fails to do any operation on page load as required by the test (as per screenshot).

    When I make a switch back to Firefox browser they all work fine.

Comments are closed.