From: Biju A. <bij...@ya...> - 2003-12-08 16:27:56
|
Hi, I want to test a page which has a login form, Source code for the page is <html> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="setAction()"> <form name="loginInfo" method="POST" action="/Main/login/Login?d=def.net&l=en_US"> <p> </p> <input type="hidden" name="pinOrPassword" value="false"> <table width="90%" border="0" cellspacing="2" cellpadding="1" summary=""> <tr> <td class="formBody" width="28%"> User Name: </td> <!-- The query parameter u is used by the login:signon jsp tag. Don't change it. --> <td width="72%"> <input type="text" name="u" size="24" value=''> </td> </tr> <input type="hidden" name="d" value=' epok.net'> <tr> <td class="formBody" width="28%"> Password: </td> <td width="72%"><input type=" password" style="font-family:sans-serif" name="password" size="24" value='' ></td> </tr> <tr> <td width="28%" class=" normTxt"> </td> <td width="72%"> <input type="radio" name="ssl" value="Secure" onClick="setAction()" > <span class="normTxt"> Secure Login </span></td> </tr> <tr> <td width="28%" class="normTxt"> </td> <td width="72%"> <input type="radio" name="ssl" value="Standard" onClick="setAction()" checked > <span class="normTxt"> Standard Login </span></td> </tr> <tr> <td width="28%"> </td> <td width="72%"> <table border="0" cellspacing="0" cellpadding=" 3" class="toolHilite" summary=""> <tr> <td><input type="submit" name="submitName" value=' Log In' class="buttons" title=' Click here to log in to your account.'> </td> </tr> </table> </td> </tr> <tr> <td width="28%"> </td> <td width="72%" class=" normTxt"> </td> </tr> </table> <p> </p> </form> </td> <td width="38%" valign="top" bgcolor=" #FFFFFF"> <p> </p> <p> </p> <p class="normTxt"> To access your account, enter your user name and password and click Log In. </p> </td> I have the html Unit Test Program as follows import junit.framework.*; import com.gargoylesoftware.htmlunit.*; import com.gargoylesoftware.htmlunit.html.*; import java.net.*; public class TestMainPage extends TestCase { public TestMainPage (String dummy) { super(dummy); } public void testLogin() throws Exception { try { final WebClient webClient = new WebClient(); if(webClient.isJavaScriptEnabled()) { System.out.println ("Java Script Enabled"); } final URL url = new URL("http://def.net:8081//Main/login/Login?d=def.net"); final HtmlPage page = (HtmlPage)webClient.getPage(url); // Get the form that we are dealing with and within that form, // find the submit button and the field that we want to change. final HtmlForm form = page.getFormByName("loginInfo"); final HtmlSubmitInput button = (HtmlSubmitInput)form.getInputByName("submitName"); final HtmlTextInput textField = (HtmlTextInput)form.getInputByName("u"); // Change the value of the text field final HtmlPasswordInput pwdField = (HtmlPasswordInput)form.getInputByName("password"); // Change the value of the text field textField.setValueAttribute("biju"); pwdField.setValueAttribute("biju"); final HtmlPage page2 = (HtmlPage)form.submit(); WebResponse wr = page2.getWebResponse(); System.out.println (wr.getContentAsString()); System.out.println ((wr.getUrl()).toExternalForm()); assertEquals("Server Login Successful",page2.getTitleText()); } catch (Exception e) { e.printStackTrace(); } } protected void runTest() throws Exception { testLogin(); } } The problem is that eventhough I am giving the correct login name and password the second page is not loading and it is not displaying and error message also, the content of the page2 is always same as the page1. Help appreciated!! Thanks, Biju A __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ |
From: Mike B. <mb...@Ga...> - 2003-12-08 18:05:00
|
I'm about to head into a meeting so I don't have much time to look at this but I did notice that you are calling submit directly on the form instead of clicking on the submit button. This will not cause the submit button to be sent back to the server and may cause different results. The example is also incomplete as you reference javascript methods that aren't included here. Can you reduce the sample to a smaller one? I have lots of code that does simple form submission so it certainly does work. We just need to find out what is different in this sample and trying to reduce it would be a good step towards that. -- Mike Bowler Principal, Gargoyle Software Inc. Voice: (416) 822-0973 | Email : mb...@Ga... Fax : (416) 822-0975 | Website: http://www.GargoyleSoftware.com |
From: Biju A. <bij...@ya...> - 2003-12-08 19:48:18
|
I tried with both the form.submit() and button.click() method but it doesn't make any difference on the output. I have also code which works for simple form submission but this particular page which I sent, having problem with HTML Unit. I guess HTML Unit automatically load the java script so the source code for the java script is not important in this context, as my whole aim to fill out the log in form and submit to the server. I want to automate the login of a thid party web site through HTML Unit, for acceptnace testing, I don't have any control over the source for the page, except viewing source. Thanks, Biju Arjunan --- Mike Bowler <mb...@Ga...> wrote: > I'm about to head into a meeting so I don't have > much time to look at > this but I did notice that you are calling submit > directly on the form > instead of clicking on the submit button. This will > not cause the > submit button to be sent back to the server and may > cause different results. > > The example is also incomplete as you reference > javascript methods that > aren't included here. Can you reduce the sample to > a smaller one? > > I have lots of code that does simple form submission > so it certainly > does work. We just need to find out what is > different in this sample > and trying to reduce it would be a good step towards > that. > > -- > Mike Bowler > Principal, Gargoyle Software Inc. > Voice: (416) 822-0973 | Email : > mb...@Ga... > Fax : (416) 822-0975 | Website: > http://www.GargoyleSoftware.com > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux > Tutorials. > Become an expert in LINUX or just sharpen your > skills. Sign up for IBM's > Free Linux Tutorials. Learn everything from the > bash shell to sys admin. > Click now! > http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ |
From: Mike B. <mb...@Ga...> - 2003-12-08 21:37:14
|
Biju Arjunan wrote: > I guess HTML Unit automatically load the java script > so > the source code for the java script is not important > in this context, as my whole aim to fill out the log > in form and submit to the server. The html that you provided does not have any script tags so I have no idea how you expect it to load a javascript file. I don't see anything immediately wrong but you haven't provided enough context to reproduce the problem. > I want to automate the login of a thid party web site > through HTML Unit, for acceptnace testing, I don't > have any control over the source for the page, except > viewing source. Is this a publicly accessible website? Are you able to post the url? -- Mike Bowler Principal, Gargoyle Software Inc. Voice: (416) 822-0973 | Email : mb...@Ga... Fax : (416) 822-0975 | Website: http://www.GargoyleSoftware.com |