Saturday 4 August 2012

Getting started with automated web-interface testing

If you have a complex system with lots of interdependent components it is easy to break things whenever you change anything. This means whenever anything changes you have to go through your entire system to check for breakages or 'regressions'.

Thankfully, for web-applications there is selenium.

The selenium IDE (SIDE) is a firefox plug-in taking about 2 minutes to install and is very easy to use. It is great for recording the individual steps you go through to do a test: open this page, click on that link, type these values into a form, verify the results are as they are supposed to be. Just push the red record button and SIDE will start adding rows to your test script. You will also get extra options in your context menus that let you do extra things like "verify text present". Using SIDE it is very simple to record the steps you normally go through to test a component of a website.

Once you have recorded a simple test sequence you can save the test and replay it as you like (setting the start and end/break points). The SIDE lets you cluster a bunch of individual tests into a group or test suite.

The tests recorded by the SIDE are stored as a simple 3 column table. The SIDE itself stores them in a html table, allowing you to easily cut and paste the individual rows to "edit the script" as you like.The SIDE displays your test scripts either a neatly formatted table, or as raw html - I've found it works well to just open the file directly in the browser to be presented with a simple table that can be cut and paste.

So what are the challenges?
  1. Avoiding brittle tests - ie you want your tests to fail because something is wrong, not because your website has changed. The trick here is use well thought through locators to describe to selenium what part of the page you are referring to, and also to use smart pattern matching when "verifying text is present". Even though SIDE won't record great locators and text patterns for you, it is easy to over-write the initial values SIDE records. All the power of regular expressions and CSS/DOM/XML locators is at your finger tips.
  2. Managing the high level organisation of tests. This is really beyond the capacity of the SIDE. Think of making a comprehensive test battery for a large site as analogous to making a TV series. The role of the SIDE is to act as video camera enabling you to rapidly gather footage. Once the hours of footage are shot it needs to go through the special effects department and editing room. It turns out this editing process is pretty painless. You're in an environment that produces html pages for breakfast right? Managing you test suite is just as simple. That said, there are lots of naff TV series out there.
Next step? First of all download the SIDE and record a bit of footage. 

No comments:

Post a Comment