Saturday, 15 December 2007

Webapplication testing like a Lego story

Once I have got the chance to challenge the joys and woes of testing a Webapplication.
I started the whole thing trying out HttpUnit/HtmlUnit and Selenium to experience which one is better for me.
I decided to use Selenium because it uses a real browser for clicking throughout the UI, therefore if the UI works driven by tests it will work in the hands of human users too.

I used the Selenium IDE to create my initial test cases and I saved them as Java test cases. Later as the number of test cases increased the same Selenium IDE generated java code appeared across several test cases. I refactored those repeating code until I had only one helper method for handling the UI elements. From then on writing test cases was like playing Lego in my childhood, except that instead of using the Lego brick I used the methods in my helpers. The number of test cases has grown to a few hundred in one month. Well, playing Lego becomes boring after a certain amount of time.
Fortunately I faced another challenge.

I needed to check if handling the mandatory fields, on forms works or not. Therefore I started to play with my lego set again. After writing the second test case I saw that they are almost identical. Hm... I decided to build a generic machine for testing those forms. In two weeks the machine was up and running and every form was well tested (around 300 cases).
In the meantime the way how the requirements were defined for the mandatory fields had changed from text based sentences into a big matrix. Usually changing letters in matrixes are much more easier than rewriting whole sentences right? So the requirements/matrix changed on every two-three days. All I needed to do was to change one or more letters from "r" to "m" in my test case to support those changes. Yes, my machine was data driven. Not to bad from a Lego system. :)

That was the funny part for a developer like me who was asked to test a web ui.

The whole thing was still under development and fine tuning. Therefore, I wanted to put those tests to check the ui every day automatically. The machine which was given to me for daily regression testing was running linux. It was placed somewhere maybe without a monitor and a keyboard.

Well, my idea was to test it under firefox but I was constrained to use only the text console. Hm... How those two fit together. Fortunately I got a hint from a friend to use a virtual display.
I used the Xvfb for the virtual display.

In this way the cron job could launch the test cases which could open a running fully functional firefox and the webapplication was tested every day. :)

Well, in the beginning I did't want to do all this "testing", but during the journey I gained a lot of experience and I say it worth playing all this Lego like game. :)