I'm testing HtmlUnit for a component we're writing that will be dealing with HTML and XML from a website. It seems to fail when the BrowserVersion of WebClient is FIREFOX_2.
(The settings.xml below is just a sample maven settings.xml file on my machine. Any valid xml file will do for this test)
This works:
final WebClient webClient = new WebClient();
final XmlPage page = (XmlPage) webClient.getPage("http://127.0.0.1/settings.xml");
And this:
final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
final XmlPage page = (XmlPage) webClient.getPage("http://127.0.0.1/settings.xml");
This fails:
final WebClient client = new WebClient(BrowserVersion.FIREFOX_2);
final XmlPage page = (XmlPage) webClient.getPage("http://127.0.0.1/settings.xml");
and throws exception:
11/03/2008 11:29:57 com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1 run
SEVERE: Exception while initializing JavaScript for the page
java.lang.ClassCastException: com.gargoylesoftware.htmlunit.xml.XmlPage cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlPage
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init(JavaScriptEngine.java:225)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$000(JavaScriptEngine.java:96)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.run(JavaScriptEngine.java:156)
at org.mozilla.javascript.Context.call(Context.java:577)
at org.mozilla.javascript.Context.call(Context.java:499)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:167)
at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1084)
at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:115)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createXmlPage(DefaultPageCreator.java:172)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:95)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:450)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:395)
I also tested this with one of the unit tests in HtmlUnit - testValidDocument. It makes use of testXmlDocument - modified that so instead of WebClient(), it uses WebClient(BrowserVersion.FIREFOX_2)
Unit test fails after that change.
Logged In: YES
user_id=402164
Originator: NO
Thanks for reporting.
The problem as been fixed since HtmlUnit-1.14 (see http://htmlunit.sourceforge.net/gettingLatestCode.html for how to get the latest snapshot)