Missing history update when clicking on links in GWT and HtmlUnit unittests

I’m still pretty enthusiastic about the benefits of templating [1] GWT UIs with HTML as it turns out to be a productive way for altering UIs without going through a tedious compilation and deployment procedure.

HtmlUnit 2.9 is a great java browser for integration-testing Ajax applications. It works fine with GWT and we use it a lot at Bazarooma because it allows us to test any user interaction in a matter of seconds. In conjunction with the particular approach to HTML templating we noticed a peculiar problem with HtmlUnit: assuming there is an inner link in the page such as

Site overview

which we wrapped in a Hyperlink, then the following code

HtmlAnchor e = (HtmlAnchor)page.getFirstByXPath("//a[@id='overview']");
HtmlPage page = e.click();

will not trigger a history event and the application does not react to that simulated click. It turns out that by not wrapping the link into an Hyperlink instance programmatic clicks work just fine even in HtmlUnit.

Resources

[1] Speeding up initial page view of Ajax applications with static HTML
http://georgovassilis.blogspot.com/2012/03/speeding-up-initial-page-view-of-ajax.html

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s