JWebUnit is a web application testing framework written in Java, which essentially tries to provide a simple API to the powerful HtmlUnit framework. I am a committer to the project.

  1. peer not authenticated

Google Maps

By default, JWebUnit can’t handle Google Maps, because the Google Maps Javascript has a syntax error. One solution is to turn off throwing script exceptions:

protected void setUp() throws Exception {
  HtmlUnitTestingEngineImpl engine = (HtmlUnitTestingEngineImpl) getTestingEngine();

  // continue as normal...

However, this means that ALL script exceptions will be hidden, which is usually not a good thing - you should try and catch script exceptions for your own code. So, you should only use the above code when it is absolutely necessary (I use a mocking approach).


To use the NicelyResynchronizingAjaxController in your JUnit 4 project, you can use the following code:

public void testSearchWithEmptySearchString() {
	if (getTester().getTestingEngine() instanceof HtmlUnitTestingEngineImpl) {
		((HtmlUnitTestingEngineImpl) getTester().getTestingEngine()).getWebClient().setAjaxController(new NicelyResynchronizingAjaxController());
	// ...
  1. Running arbitrary Javascript
((HtmlPage) ((HtmlUnitTestingEngineImpl) getTestingEngine()).getCurrentWindow().getEnclosedPage()).executeJavaScript("alert('hello, world!');");