Selenium

There are good tools for testing most parts of web applications. At the base level, almost every language has a unit testing framework. Above that, some web frameworks, like Rails, add functional tests.

Further out, there all sorts of tools you can use to send requests to your application and analyze the results. Some are quite sophisticated, and can identify the smallest changes (just one byte for example) in your application’s responses over time. Its great for regression tests and take almost no time once you’ve set up all your tests.

And of course there are lots of performance testing frameworks that try to stress your application to see how it performs under load.

One thing that has been difficult though is testing code that runs in a browser. Since what runs in the browser _is_ the application to users, you have to get it right. Complicating the effort are the myriad of differences between browsers, not to mention the differences in a single browser running on different operating systems.

Last time I was involved with a major web application, there really weren’t any tools, either open source or commercial, to test the client. Mercury hadn’t yet launched its web testing tools, and the rest of the commercial ones were only good at sending and recieving responses to a web application.

Happily, this has changed. My favorite is Selenium, which supports all major browser. There is even a Firefox extension that helps you quickly write tests by recording what you are doing in the browser. Tests are saved as HTML tables – which sounds weird, but works quite well.

Selenium will load your tests and then run them inside a browser. Its quite entertaining watching your browser do things without you typing or clicking any buttons.

One of the nice things about Selenium is how easy it is to extend. For example, we needed to have precise control over where mouse events happened on the screen (i.e., the x and y locations). Selenium doesn’t support this, but an hour later I had hacked together everything I needed.

If your interested, I’ve [submitted](http://jira.openqa.org/browse/SRC-65) the code back to the selenium project. Simply download it and paste it into your user-extensions.js file and you’re ready to go.

And if you’re using Rails, check out the selenium on rails project which nicely integrates selenium into your application (it also needed a couple of patches to suport Mongrel and to record test results, I’ll submit those also).

Leave a Reply

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

Top