From: John L. <joh...@ca...> - 2003-03-13 21:31:02
|
I am a novice to HtmlUnit and as a first exercise, wrote a test program based closely on "Submitting a Form" from this page: http://htmlunit.sourceforge.net/gettingStarted.html The formo on my test HTML page features three inputs: text, password, submit. I set the text and password using setValueAttribute, and then attempt to submit the form. When I execute this command: final HtmlPage page2 = (HtmlPage)button.click(); I get this compile warning: [INFO] HttpMethod - -Redirect requested but followRedirects is disabled So I then imported java.net and asked this question: assertEquals(HttpURLConnection.getFollowRedirects(), true); Yes, indeed FollowRedirects is set to true. And yet the warning claims it is disabled. Ultimately, I was not able to submit the form. Thoughts? |
From: John L. <joh...@ca...> - 2003-03-14 17:25:27
|
An additional issue issue. I am doing a form-based login where the web page is constructed as follows: <form NAME="j_security_check" ACTION="j_security_check" METHOD="POST"> ... <input type="text" value="value1" name="j_username" /> ... <input type="password" value="value2" name="j_password" size="10" maxlength="15" /> ... <input TYPE=submit NAME="login" VALUE="Login"> </form> [ Note, I am initializing the login and password inputs to a VALID set of values. ] The underlying JSP code invokes a second page via the Login post along these lines: response.sendRedirect("j_security_check?j_username="+login+"&j_password="+pass); I press the Login button and it brings me to the second page (because it is successful). The server log is as follows: 192.168.1.15 - value1 [14/Mar/2003:16:16:50 +0000] "POST /order/j_security_check HTTP/1.1" 302 0 "http://john.candata.com/order/Login.jsp;jsessionid=5ifh899gfnnb0" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826" When I do the same thing via HtmlUnit, for some reason, it is not passing in the login and password values. It passes all the assertion tests except the final one indicating a successful login to the second page. It is a login failure, and I am returned back to the original page. final HtmlForm form = page1.getFormByName("j_security_check"); final HtmlSubmitInput button = (HtmlSubmitInput)form.getInputByName("login"); final HtmlTextInput textField = (HtmlTextInput)form.getInputByName("j_username"); final HtmlPasswordInput pwdField = (HtmlPasswordInput)form.getInputByName("j_password"); assertEquals("value1, textField.getValueAttribute()); assertEquals("value2", pwdField.getValueAttribute()); final HtmlPage page2 = (HtmlPage)button.click(); assertEquals("Second Page", page2.getTitleText()); The server log does not indicate the value of the Login input, as it does when I manually log in. 192.168.1.15 - - [14/Mar/2003:16:20:17 +0000] "POST /order/j_security_check HTTP/1.1" 302 0 "-" "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)" I thought maybe Java.net.authenticator - setting Login and Password - might solve the problem, but the effect was the same. The login failed and I did not reach second page. webClient.setCredentialProvider(new SimpleCredentialProvider ("value1", "value2")); Hints? |
From: Mike B. <mb...@Ga...> - 2003-03-14 18:40:19
|
> 192.168.1.15 - value1 [14/Mar/2003:16:16:50 +0000] "POST > /order/j_security_check HTTP/1.1" 302 0 > "http://john.candata.com/order/Login.jsp;jsessionid=5ifh899gfnnb0" > "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826" Is that really a semi-colon after Login.jsp and not a question mark? If the browser is accepting a semi-colon and treating it like a question mark then this would be the reason HtmlUnit is showing different behaviour. Is there any way that you can get a tcp dump of the initial response? I'd like to know what the value of the "Location" header is when HtmlUnit recieves the 302 redirect code. If you're up to putting some printlns in the HtmlUnit code, the redirection logic is in WebClient.java starting on line 930. -- Mike Bowler Principal, Gargoyle Software Inc. Voice: (416) 822-0973 | Email : mb...@Ga... Fax : (416) 822-0975 | Website: http://www.GargoyleSoftware.com |
From: John L. <joh...@ca...> - 2003-03-14 21:47:09
|
A followup. I downloaded version 1.2 from CVS. Inserted the location printline as instructed and got this printing out: [junit] Location string is:http://john.candata.com/order/Login.jsp;jsessionid=1if6pf3ykdwqk [junit] Location string is:http://john.candata.com/order [junit] Location string is:http://john.candata.com/order/ The wrinkle in this is that with the locally-compiled version 1.2, my test script executes exactly as it should. Hence, no more problems. |