From: Bhupesh R. S. <bhu...@vi...> - 2005-04-19 09:08:41
|
I am migrating from HttpUnit to HtmlUnit. I am trying to login to my application from HtmlUnit. =20 Here is the test case. =20 public void testHtmlUnit() throws IOException=20 { WebClient wc =3D new WebClient(); wc.setRedirectEnabled(true); URL url =3D new URL("http://localhost:8080/abc/abc_frameset.jsp"); HtmlPage page =3D (HtmlPage)wc.getPage(url); =20 HtmlForm form =3D page.getFormByName("mainForm"); HtmlSubmitInput loginButton =3D (HtmlSubmitInput)form.getHtmlElementById("loginButton"); HtmlTextInput username =3D (HtmlTextInput) form.getInputByName("j_username"); HtmlPasswordInput password =3D (HtmlPasswordInput) form.getInputByName("j_password"); username.setValueAttribute("zdpm_admin"); password.setValueAttribute("zdpm_admin"); HtmlPage page2 =3D (HtmlPage) loginButton.click(); //System.out.println(page2.toString()); =20 } =20 When I run it, I get the following exception. =20 =3D=3D=3D=3D=3D=3D=3D EXCEPTION START =3D=3D=3D=3D=3D=3D=3D=3D EcmaError: lineNumber=3D[148] column=3D[0] lineSource=3D[null] name=3D[TypeError] sourceName=3D[/abc/jscripts/navbar.js] message=3D[TypeError: Cannot set property "cols" of null to "0,*" (/abc/jscripts/navbar.js#148)] com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "cols" of null to "0,*" (/abc/jscripts/navbar.js#148) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(J avaScriptEngine.java:344) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeOnLoadHandlersIfNeede d(HtmlPage.java:953) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:158 ) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.ja va:701) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:361) . . . The line 148 of navbar.js has the following code. hideLeftnav() method is called from the onLoad event. =20 146 function hideLeftnav() { 147 var bottom =3D getFrameset("bottom") ; 148 bottom.cols=3D"0,*"; 149 } =20 my frameset looks like this. =20 <frameset id=3D"application" title=3D"Application" rows=3D"60,0,*" framespacing=3D"0" frameborder=3D"1" > <frame noresize id=3D"navbar" name=3D"navbar" src=3D"<%=3D navbar = %>" marginwidth=3D"0" marginheight=3D"0" scrolling=3D"no" frameborder=3D"0"> <frame noresize id=3D"subnavbar" name=3D"subnavbar" src=3D"subNavblank.jsp"=20 marginwidth=3D"0" marginheight=3D"0" scrolling=3D"no" frameborder=3D"0"> <frameset id=3D"bottom" title=3D"bottom" cols=3D"<%=3D bodysize %>" framespacing=3D"0"> <frame class=3D"leftNav" id=3D"leftNav" name=3D"leftNav" noresize src=3D"<%=3D leftnav %>" marginwidth=3D"0" marginheight=3D"0" frameborder=3D"0" scrolling=3D"auto"> <frame class=3D"workArea" id=3D"workarea" name=3D"workArea"=20 marginwidth=3D"0" marginheight=3D"0"=20 scrolling=3D"auto" frameborder=3D"0" src=3D"<%=3D = workarea %>"> </frameset> </frameset> =20 Apparantly getFrameset("bottom"); is returning null. But when I run it from the browser (IE 6), it is working fine. It is working even from the HttpUnit test case. Can anyone explain why this is happening. =20 also i am getting lot of warnings and info's on my console. some of them include =20 =20 Apr 19, 2005 10:45:43 AM com.gargoylesoftware.htmlunit.html.HtmlPage loadJavaScriptFromUrl WARNING: Expected content type of text/javascript or application/x-javascript for remotely loaded javascript element http://localhost:8080/abc/errors/images/login.js <http://localhost:8080/abc/errors/images/login.js> but got [text/html] Apr 19, 2005 10:45:45 AM org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded INFO: Redirect requested but followRedirects is disabled =20 I have explicitly added webClient.setRedirectEnabled(true); in my code. but why i am still getting the INFO: Redirect requested but followRedirects is disabled. =20 What does the warning Expected content type of text/javascript but got [text/html] means. =20 =20 |