Disabling Javascript in JWebUnit

Add another to my bounty of reasons for avoiding Javascript. This is not a problem with Javascript as such, more-so a problem with web functional testing tools. Still if you don’t use Javascript, you won’t have these and many other problems the most notably being cross-browser compliance issues.

So, to the problem; In my efforts to grow a virtually non-existent set of acceptance tests, I was after a way to disable Javascript in JWebUnit. Google told me this:

HttpUnitOptions.setScriptingEnabled(false);

Great, that was easy.

It seemed to work. Then enter ludicrously complex Javascript date selection pop-up. It appeared as if scripts were running again, so I investigated and discovered on each of the following WebResponse methods HttpUnit reloads all page elements, including attempting to load and execute scripts *Deep Breath*:

getForms, getLinks, getApplets, getImages, getTextBlocks, getTables, getElementsWithName, getElementsWithAttributes, getElementNames, getElementsByTagName, getElementsWithID, getFrames

Phew! That’s plenty of opportunity for a page to get reloaded. Given it’s possible to invoke these many times interrogating the one web response, how can this strategy be a good thing? Why re-assemble the entire page just because I want to retrieve elements by id for instance? If the answer is ‘Just in-case Javascript has done it’s dirty-work in the meantime’, damn, I hope there is a better way. Surely the performance effects are very significant. Significant enough to at least make you think twice when tempted to use these methods.

So add another to my pile of reasons for hating Javascript. Oh, and does anyone have any idea why disabling Javascript in HttpUnit does not disable this reloading feature? Any answers much appreciated.

Leave a Reply