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/ |