Skip to content

Instantly share code, notes, and snippets.

@searls
Created December 17, 2010 14:26
Show Gist options
  • Save searls/745009 to your computer and use it in GitHub Desktop.
Save searls/745009 to your computer and use it in GitHub Desktop.
HtmlUnit's documentation doesn't make it abundantly clear how to run assertions against an HTML string snippet (i.e. the easiest way to run tests when you don't care about URLs, network connections, etc.)
private HtmlPage getPage(String html) {
MockWebConnection webConnection = new MockWebConnection();
webConnection.setDefaultResponse(html);
WebClient webClient = new WebClient();
webClient.setWebConnection(webConnection);
try {
return webClient.getPage("http://blah");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment