Articles

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. javax.net.ssl.SSLPeerUnverifiedException: 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:

@Override
protected void setUp() throws Exception {
  HtmlUnitTestingEngineImpl engine = (HtmlUnitTestingEngineImpl) getTestingEngine();
  engine.setThrowExceptionOnScriptError(false);

  // continue as normal...
  super.setUp();
}

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).

NicelyResynchronizingAjaxController

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

@Test
public void testSearchWithEmptySearchString() {
	beginAt("/");
	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!');");