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 FINN.no 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.

Rhino fork: HtmlUnit-core-js

HtmlUnit has now started a fork of the Mozilla Rhino JavaScript engine.

HtmlUnit uses Rhino as its core JavaScript engine (roughly speaking what is covered by the ECMA specification: the objects Object, String, Date, Number, … but not the DOM objects like Document, Window, … that are defined by HtmlUnit). Most of the work to simulate browser’s JavaScript processing resides in the browser specific objects and Rhino does a really good job as core JavaScript engine.

Nevertheless we are blocked by some issues in Rhino that don’t get fixed - or not quickly enough - even when we propose patches (for instance bug 412928). As discussed in Rhino mailing list [1] this seems to come from a lack of resources on Rhino’s side as well as from a slightly different focus: for us the most important is to simulate browser’s behaviour whereas speed and respect of ECMA standard are very important for Rhino.

Releases of htmlunit-core-js will be made available at the same time than future HtmlUnit releases.

My biggest hope for this project is… to be able to declare it dead and useless as soon as possible, once Rhino fills all our need. For this purpose, we will continue to open issues and provide patches to the Rhino project to help improving it.

[1] Rhino mailing list thread “Rhino project (half) asleep?

HtmlUnit 2.1 released

This time HtmlUnit committer Daniel Gredler has been faster to blog about it! ;-)

HtmlUnit 2.1 is now available. We’ve put this release less than 2 weeks after version 2.0 to quickly fix some performance problems that occurred with HtmlUnit 2.0 in CSS processing (users have reported that 2.1 runs up to 5 times faster than 2.0). Additionally this release contains a few improvements and bug fixes as documented in the change log.

HtmlUnit 2.0 released

Four months after release 1.14, I’m glad to announce the availability of HtmlUnit 2.0. Thanks to everyone who has contributed to this release and particularly to the committers Ahmed Ashour and Daniel Gredler.

From the large list of improvements contained in this release, following are particularly important:
- first release to target Java 5: HtmlUnit now makes intensive usage of Java 5 features, particularly of generics
- HtmlUnit DOM now implements org.w3c.dom.* making interaction with 3rd party libraries easier
- improved support for incorrect HTML code
- and as always a very large number of improvements in JS support with a major achievement: the GWT 1.4 tests now pass when simulating Firefox as well as when simulating Internet Explorer!

This major release contains a few incompatible changes and can’t be dropped as a replacement of HtmlUnit-1.14.

NekoHTML 1.9.7 released

Release 1.9.7 of NekoHTML is now available.

Besides a few bug fixes, the main changes are internal: no reflection is used any more to ensure compatibility with different Xerces versions having different and incompatible methods. I’ve introduced the usage of a “bridge” per Xerces version inspired from Rhino’s VMBridge. It was a really interesting exercise to set this up and to compile and test it correctly (furthermore with JDK 1.3 compatibility).

HtmlUnit now works with GWT 1.4!

It is a common misconception about HtmlUnit to think that it doesn’t support AJAX. AJAX per itself (ie XMLHttpRequest) is supported since a long time. What is more tricky is to support all the advanced JavaScript functionalities used by the so-called AJAX libraries. To ensure that HtmlUnit correctly emulates the browsers’ behaviour (currently Firefox 2, Internet Explorer 6 & 7) we have integrated the test suites or demo applications of different AJAX libraries in HtmlUnit build and many of them already pass correctly.

GWT 1.4 has been long a source of problems but, as announced by HtmlUnit committer Ahmed Ashour last week, this is now past story: HtmlUnit is now able to work correctly with the example applications of GWT 1.4!

Stay tuned, HtmlUnit 2.0 will be released soon.

NekoHTML 1.9.6.2 released

I’ve just released version 1.9.6.2 of the HTML scanner NekoHTML.

This release fixes the JDK 1.3 compatibility problems that occurred in previous 1.9.6.x releases and introduces experimental features to facilitate handling of malformed HTML code as well as to push new source for immediate parsing. These two features should allow HTMLUnit to fix some of its oldiest bug requests.

ClamAV Grails plugin

Finally I’ve released my first Grails plugin: ClamAV Grails plugin. It allows to easily use the Open Source antivirus ClamAV from Grails through a service and a validator.

The freeOfVirus validator can be used like any other constraints:


class Foo
{
  ...
  byte[] myBinaryData
  …
  static constraints = {
    myBinaryData(freeOfVirus: true)
  }
}

Simple, isn’t it?

Boost your WebTests: 50% faster or more!

Tests never run fast enough!

This is particularly true for functional tests of web applications. WebTest is known to be very fast compared to other functional test tools, nevertheless when your test suite grows or simply when you want to quickly receive feedback after a commit, you often feel that tests are too slow. A new experimental feature of WebTest allows to specify the number of threads that should be used for the tests what can bring enormous speed improvements without modification of the tests.

Simply configure the number of threads

Rather than just calling


ant

you just specify the number of worker threads


ant -Dwt.parallel.nbWorkers=20

The optimal number of worker threads will depend from the usage.

How it works: enqueue rather than execute

The idea is quite simple and the implementation totally non-intrusive. In fact this is a shame that nobody has had the idea previously (including you! ;-)). This can be simply explained with a few lines of code.

WebTest is based on Ant what means that the task mapped to <webtest> contains something like this:


class WebTestTask extends Task
{
  void execute()
  {
     // do the WebTest
  }
}

For the parallel execution we map <webtest> to a new class that looks like this:


class WebTestTaskParallel extends WebTestTask
{
	void execute()
	{
		workQueue.add this
	}

	void executeReally()
	{
		super.execute()
	}
}

Once this is done, Ant can do its job normally. When it calls the execute() method of the task, the instance adds itself to a queue and the execute() method returns allowing Ant to continue its normal execution. A set of worker threads look at the queue, calling executeReally() on the WebTestTask instances to really run the tests. That’s nearly everything, the rest is just synchronization glue code.

Improvements from 0% to 50% and more

I’ve seen many cases where using a few threads allows to gain over 50% execution speed. In fact this will depend from the capacity of the application under test and how it can handle the increased charge. With a server - not necessary fast - that smoothly handles the charge generated by numerous worker threads, I can imagine tests suites that execute approximatively in the time of the slowest test. On the other side I’ve already seen test suites that take more time to execute with many worker threads when the AUT runs on the same physical machine than the tests themselves. It’s not really surprising: if the tests need more “power” to execute, then there is less for the application.

Limitations

With a recent WebTest build, you just have to specify the number of worker threads to start using this new feature. You many need to refactor your tests to include processing made after a </webtest> within the test otherwise this will be done before the tests itself gets executed and may be the cause of problems. Finally current implementation of this feature doesn’t contain any facility to manage dependencies between tests.

Towards functional load testing?

Tests with large numbers of worker threads have shown that WebTest scales quite well: both memory and CPU usage stay correct. This opens a new perspective for WebTest: the usage as load testing tool. In fact it should probably be bound to something like JMeter but I see great advantages in WebTest usage compared to low level http processing as usually done by load testing tools, particularly in test maintainability, AJAX testing or for the correctness of the simulated scenario.

Update (Feb 6): a former client told me that they just started to use a slightly modified version of this feature I prepared them for some time (allowing to manage some dependencies between tests). The results are even better as expected: over 75% saved time! With 8 working threads the tests complete in less than 25% of the original time.

HtmlUnit 1.14 released

The HtmlUnit team is pleased to announce the release of HtmlUnit 1.14.

This release contains a really large number of improvements in JavaScript support and in execution speed plus bugs fixes and new functionalities. Have a look at the change log for more details, the list is quite impressive.

This is the last version that targets Java 1.4. Next release will target Java 5 and make plain usage of Java 5 features.

« Previous entries