HtmlUnit in .NET and HtmlUnit in JRuby with Celerity as fast compatible alternative to Watir

Java and Groovy are my main programming languages (as well as JavaScript for scripts in HTML pages) therefore it’s always funny for me to see that HtmlUnit gets used outside my “Java world”.

HtmlUnit in .NET

HtmlUnit is a Java library but its usage seems not limited to the JVM. For some time I found the blog post “Some Goodies: Model-View-Presenter Article, Java in .NET, HtmlUnit” where the author describes how he successfully used IKVM to use HtmlUnit from his .NET environment. Quite funny.

HtmlUnit in JRuby: Celerity as faster Watir

The initial setup for the second example was surely simpler as it runs on the JVM. The Norwegian provider had performance problems with its Watir test suite completing in 3 hours which is not very agile. To improve this situation, they decided to create the Open Source project Celerity to provide a Watir-compatible API wrapping HtmlUnit to improve execution speed without to rewrite all their tests. It would be interesting to know how fast their suite now runs and if they use new possibilities of this approach like running tests in parallel.

The Celerity project perfectly demonstrates that speed matters. You can frequently find “experts” writing that functional tests are slow per nature. This is fully wrong, functional tests won’t be as fast as unit tests but HtmlUnit and derived tools (like Celerity, WebDriver with HtmlUnit driver, WebTest) demonstrate that functional tests can be quite fast.

.NET, JRuby, and then?

The interest for HtmlUnit continually grows and I’m curious to see what will be the next “exotic” usage of HtmlUnit. Don’t hesitate to communicate your experiences.



  1. kranthi said,

    May 9, 2008 at 6:23 pm


    I am new to HTMLUNIT….i have tried running a code but it is giving some errors.can u please help me out.

    public static void testHomePage() throws Exception

    System.out.println(“HI 1”);
    final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2);
    System.out.println(“HI 2”);
    final HtmlPage page = (HtmlPage) webClient.getPage(“”);
    System.out.println(“Title of the page is ” + page.getTitleText() );

    I get message upto “HI 2″..but after that the error being displayed is …

    May 9, 2008 11:51:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
    INFO: I/O exception ( caught when processing request: Connection timed out
    May 9, 2008 11:51:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
    INFO: Retrying request

    Thanking u in advance

  2. Marc Guillemot said,

    May 12, 2008 at 11:32 am

    Kranthi, the best place for questions about HtmlUnit usage is surely HtmlUnit’s user mailing list and not this blog.

  3. Jari Bakken said,

    May 13, 2008 at 3:33 pm

    We have posted some early benchmarks for Celerity vs. Watir here:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: