Testing with HTMLUnit

Has anybody ever tried testing an app with
HtmlUnit
framework? I didn’t getting javascript that loads components running well…

Thanks in advance…

There has been quite a lot of work done with HTMLUnit framework. One of the challenges is to use “waitForVaadin()” method - see
http://vaadin.com/forum/-/message_boards/message/236584
.

Anyone who has been using HTMLUnit in practice with Vaadin care to comment?

Hi Victor!

I’ve been working quite some time on getting HTMLUnit to play nicely with Vaadin applications and I might be able to help. As you probably know HTMLUnit relies on Rhino for javascript execution and while Rhino handles some javascript perfectly there are, unfortunately, often problems.

I’m guessing the problems you are experiencing arise when you try to access DOM elements that don’t exist before the javascript has finished executing. However, please correct me if I’m mistaken.

All javascript is executed in a thread in the background, which means you have to wait for it to finish before doing anything else. This can be done by: 1) inserting a sleep statement before each operation that uses the DOM or 2) calling the waitForVaadin() method using the code snippet previously mentioned by Joonas. Now, if you are doing functional testing, where you don’t care about how long it takes to perform the tests, I would encourage you to pick alternative one. Simply because it’s so easy to implement and it works well. Otherwise, you should start looking in to executing javascript manually.
The HtmlUnit API documentation
might help.

A third option might be to use a method called
waitForBackgroundJavaScript()
, which (if it works) looks it might be exactly what you need. I haven’t tried this myself however, so I have no idea if it works or not. It would be nice to hear about the results if you decide to give it a shot!