tommorris.org

Discussing software, the web, politics, sexuality and the unending supply of human stupidity.


Watir, WebDriver, PhantomJS

There’s been some excitement about CasperJS recently. I mean, exciting exciting exciting: you can write your front-end tests in JavaScript!

Well, I’ve got something even more exciting: you don’t have to write your front-end tests in JavaScript. You can write them in Python or Ruby or some other language that doesn’t make you want to stab nails into your eye.

For a long time, I’ve been a fan of Watir, a Ruby library that basically drives a web browser (Firefox usually, but you can substitute Safari or Chrome if you prefer). Well, here’s where it gets even more awesome. Watir now uses WebDriver, a protocol to talk to the browser that has been spun out of Selenium.

And PhantomJS implements the WebDriver protocol.

What this means is headless Watir testing. Nothing funky needed. No rewriting them all in gimpy horrible JavaScript.

Here’s the install instructions for OSX

I got it running on my Ubuntu server. I just had to download the PhantomJS binary, copy it into /usr/local/bin/, install the watir-webdriver gem, install the libfontconfig package with Aptitude and boot up PhantomJS manually using phantomjs --webdriver=8910

There’s only one thing better than headless browser testing in JavaScript, and that’s headless browser testing without JavaScript.