How to get married with HtmlUnit

  4 posts   Feedicon  
Replies: 3 - Last Post: May 20, 2009 20:16
by: Jason Lee
showing 1 - 4 of 4
 
Posted: May 07, 2009 09:16 by IngoHofmann
Hi guys,

FacesTester is a real cool and lightweight tool. Together with HtmlUnit (http://htmlunit.sourceforge.net/) I could get a powerful web testing framework.

As FacesTester provides the (page).getRenderegPage() method, you can use the return value for (only one possibility):

public HtmlPage getHtmlPage(boolean javaScriptEnabled, String renderedPage) throws IOException {

URL dummyUrl = new URL("http://localhost/dummy.xhtml");
WebClient dummyClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_7);
dummyClient.setJavaScriptEnabled(javaScriptEnabled);
dummyClient.setTimeout(10000); //10 seconds

// Proxy
if (Boolean.getBoolean("proxySet")) {
ProxyConfig proxyConfig = new ProxyConfig();
proxyConfig.setProxyHost(System.getProperty("http.proxyHost"));
String port = System.getProperty("http.proxyPort");
proxyConfig.setProxyPort(
Integer.getInteger("http.proxyPort"));
dummyClient.setProxyConfig(proxyConfig);
}

WebWindow dummyWindow = new TopLevelWindow("dummyWindow", dummyClient);
StringWebResponse dummyResponse = new StringWebResponse(renderedPage,
dummyUrl);

HtmlPage htmlPage = HTMLParser.parse(dummyResponse, dummyWindow);

return htmlPage;
}


(btw, it's a pity that this forum just ignores the "code" BBCode)

Cheers,
Ingo
 
Posted: May 20, 2009 04:08 by Jason Lee
Ingo, that's really cool code. I've been aiming at that from the beginning, but haven't had the time to look into it. I'll have to study your sample and see if/how we can integrate that into FacesTester itself. It might be that this is sort of integration is done by the user, but we'll see what we can do.

Thanks, again. This is really awesome.
 
Posted: May 20, 2009 07:21 by IngoHofmann
Hi Jason,
I agree with you. This should be done by the user. One drawback of HtmlUnit is that it has a lot of dependencies. FacesTester, without a HtmlUnit integration, is very lightweight and should stay so.
Best,
Ingo
 
Posted: May 20, 2009 20:16 by Jason Lee
Good point. We do need to tinker with this and perhaps create a wiki page for it. I'll get to that one of these days. Smile
Replies: 3 - Last Post: May 20, 2009 20:16
by: Jason Lee
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close