Wednesday, February 29, 2012

SWT Browser based Web Recorder

Some time ago I was playing around with Krypton - a web testing driver written by Hakan Raberg while he was working in Thoughtworks Studios and the coolness of SWT Browser component. While doing so, I realized that writing a web recorder using the SWT Browser component is quite straight forward.

I have done a simple spike that you can checkout here. I think this is a good idea because:

  • SWT Browser uses a real rendering engine (like XUL Runner for Mozilla) under the hoods. So, even though you do launch a real browser, the functionality is that of a real browser.
  • A recorder on this can use IE for recording as well, which is not possible with, say, Selenium IDE.
  • It is very fast and it integrates with superior recording capabilities of tools like Twist
While this might seem like a waste of effort - I am not going to spend the next 3 months building this! - I think if Krypton picks up, there is a good chance that this is the default Recorder implementation.

Even otherwise, I think this is a good way to show the coolness of SWT Browser component and that itself is worth the simple spike!

WaitUtils - no more arbitrary sleeps in tests

Its the year 2012 and I still see functional test code bases using Thread.sleep() at arbitrary places. Its very surprising that the person who has written this can't think of why this could be a problem (Flaky Tests) or how it can be fixed.

As mentioned in an earlier post, I have created a very simple library for Java - WaitUtils. You can checkout the code and download it from Github. Its a BSD 2 Clause licensed open source software.

The library is really simple - you always make sure you wait for some thing i.e. an event or a predicate. You never sleep without answering some basic questions. This way whenever there is a need to wait, you will do so thinking about things like:
  • What am I waiting for?
  • How long should I wait for?
  • What should I do if what I am waiting for does not happen?
Now, these look trivial, in fact, obvious. However, you would be surprised at how many functional tests do not follow this. By answering these simple questions, you can make sure that your tests are reasoned out better. 

The library intends to solve this once and for all by introducing a WaitUtils. You can download the jar, attach source and checkout the Java docs. The API is trivial and is self-explanatory.