PhantomJS+Selenium: Easy Automated Testing of AJAX-y UIs
Martin Haye and Mark Redar, California Digital Library
Web user interfaces are demanding ever-more dynamism and polish, combining HTML5, AJAX, lots of CSS and jQuery (or ilk) to create autocomplete drop-downs, intelligent buttons, stylish alert dialogs, etc. How can you make automated tests for these highly complex and interactive UIs?
Part of the answer is PhantomJS. It’s a modern WebKit browser that’s “headless” (meaning it has no display) that can be driven from command-line Selenium unit tests. PhantomJS is dead simple to install, and its blazing speed and server-friendliness make continuous integration testing easy. You can write UI unit tests in {language-of-your-choice} and run them not just in PhantomJS but in Firefox and Chrome, plus a zillion browser/OS combinations at places like SauceLabs, TestingBot and BrowserStack.
In this double-team live code talk, we’ll explain all that while we demonstrate the following in real time:
- Start with nothing.
- Install Selenium bindings for Ruby and Python.
- In each language write a small test of an AJAX-y UI.
- Run the tests in Firefox, and fix bugs (in the test or UI) as needed.
- Install PhantomJS.
- Show the same tests running headless as part of a server-friendly test suite.
- (Wifi permitting) Show the same tests running on a couple different browser/OS combinations on the server cloud at SauceLabs – talking through a tunnel to the local firewalled application.