Terminus driving multiple browsers

Conferences usually prompt me to hack on some loose thread I’ve not picked up in months. At this year’s Scottish Ruby Conference I decided I had to give a lightning talk on Terminus, my Capybara driver for scripting remote browsers. With a little hacking and lot of sitting around waiting for tests to complete, I’ve got it up to date with a lot of the latest Capybara specs and added a really simple API for switching between browsers based on name, OS, version etc.

I’m not putting out a release just yet but I thought I’d share a couple videos of it in action; one’s a hi-res screen capture and one’s a fuzzy shaky mobile capture so you can see it running across multiple machines.

The app it’s running is the Faye example application – a chat app much like Twitter. Terminus logs in as a different user on each browser, then sends messages between all the pairs of browsers and checks that each message arrives on screen in the intended browser.

Sadly, it looks like Internet Explorer support is a pipe dream for now. The XPath queries Capybara spits out are too much for my half-baked XPath engine to deal with, so unless someone comes up with a fast implementation of document.evaluate() for IE I’m leaving it alone.

Anyway, the videos:

The script that runs this is really simple, it’s just some Capybara calls with a little extra to tell Terminus to switch browsers. Check it out on GitHub.

As for what I’ve added to Terminus, here’s a quick run-down:

  • Headers and status code support
  • Multiple windows and iframes
  • Improved concurrency handling for running the same test in multiple browsers
  • Browser selection API
  • Removed the need for you to embed a script in your application
  • Very basic support for scripting remote applications

The addition of status and header support means it actually supports a superset of the behaviour supported by the Selenium driver, albeit considerably slower. The main win is being able to script remote devices – it’s great fun watching it control somebody’s iPad! Would love to see if people come up with novel uses for it.

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.