I'm trying to test website that does the following:
1. user login with their username and password
2. user can navigate to different tab, click on the tab then select the page they go.
3. under each tab, user can select certain items throught eh drop down menu, press enter
then it will give data back from database.
4. the site fromntend if all php
Iam trying to mimic this activity and have the perl test
script to go through these link, clicking, and verify the returned data.
but I am having trouble to connect the the website through
the login using Test::WWW::Mechanize. example website: http://sourceforge.net/projects/phpwebsite/
there is a login required.
here is my code
#!perl use strict; use Test::More tests => 3; use Test::WWW::Mechanize; my $agent = Test::WWW::Mechanize->new; $agent->get_ok( 'http://192.168.44.132/reporter' ); $agent->field( 'Username:', 'admin' ); $agent->field( 'Password:', 'password' ); $agent->submit_form( form_name => 'f' ); $agent->follow_link_ok( { text => 'Home', n => '1' } ); $agent->field( 'query', 'test' ); $agent->submit_form( form_name => 'f' ); $agent->follow_link_ok( { text => 'Next >>', n => '1' } );

Error msg:
00-SiteAgentStatus....ok 1/3No such field 'Username:' at C:/Perl/site/lib/WWW/M echanize.pm line 1052
how to do this? is there a better way to test >>php<< site?
thanks I used the view source and found out the this:
<script language="javascript"> function CreateI18n() { this.MUST_BE_NUMERIC="Input must be numeric and greater than ze +ro"; this.CANT_EXCLUDE="You cannot exclude a wildcard"; this.FROM="From"; this.TO="To"; this.ADVANCED_OPTIONS="Advanced Settings"; this.QUICK_OPTIONS="Basic Settings"; this.THIS_WILL_PERMANENTLY_DELETE1="This will permanently delet +e the selected entries"; this.DELETE_ALL_ENTRIES="Delete all entries in current view.\n* +** Warning! This action cannot be undone.***"; this.YOU_MUST_ENTER_USER_NAME_TO_CHANGE_PASSWORD="You must ente +r your user name and password in order to change your password"; this.ENTER_FILTER_NAME="Please enter a filter name into the fil +ter name field"; this.TO_DATE_MUST_BE_MORE_RECENT="The to date must be more rece +nt than the from date"; this.YOU_ENTERED_AN_INVALID_DATE_SEPARATOR="You entered an inva +lid date separator. It must be a single character and cannot be a spa +ce, ?, % or $."; this.YOU_MUST_ENTER_AN_ALERT_CONDITION="You must enter an alert + condition"; return this; } var I18n = CreateI18n(); </script> <html> <head> <title>Reporter - Login</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="../Resources/styles.css" rel="stylesheet" type="text/css"> </head> <body onload="document.PasswordForm.user_name_tmp.focus();" class="co +lor_link" leftmargin="0" marginheight="0" marginwidth="0" topmargin=" +0"> <!-- Menu Header --> <!-- Menu Header --> <script type="text/javascript" src="../Resources/sha1.js"></script> <script type="text/javascript" > function change_password() { hidden = document.getElementById('change_pwd'); hidden.value='on'; user_name_tmp = document.getElementById('user_name_tmp'); if (user_name_tmp.value == '') { alert('' + I18n.YOU_MUST_ENTER_USER_NAME_TO_CHANGE_PASSWORD); user_name_tmp.focus(); } else { document.PasswordForm.submit(); } } function login() { document.PasswordForm.submit(); } function sha1_password() { password_tmp_widget = document.getElementById('password_tmp_widget +'); password_tmp = document.getElementById('password_tmp'); var foo = "7cbc76df106c18e2363c552a71b6e455"; var total = hex_sha1(password_tmp_widget.value)+foo; var x = hex_sha1(total); //if (x != password_tmp.value) { password_tmp.value= x; //} } </script> <BR> <BR> <BR> <BR> <table width=600 align=center border="0" cellspacing="0" cellpadding +="0"> <tr> <td> <table border="0" align=center cellspacing="0" cellpadding="0"> <form method="post" name="PasswordForm" action="Login_veri +fy.php"> <tr width=100% height=60 valign=center > <table width=100% border=0 background="../images/loginT +itle.jpg"> <tr > <td height=60 class="HeaderPassword" colspan=2 ali +gn=center background="../images/loginTitle.jpg"> Login </td> <td height=60 > <img src="../images/loginlogoBlue.gif" alt="Login + logo" valign=top align="right" border="0"> </td> </tr> </table> </tr> <tr > <td > <table background="../images/gradient.png" width +=600 height=260 cellspacing="0" cellpadding="0" align="right"> <tr height=50 > <td align=left> </td> </tr> <tr height=70> <td> <table border=0 cellpadding=0 cellspacing +=0> <tr> <td></td> <td colspan=2> <span class=Menue>Please enter your user + name and password to login to Reporting:</span> </td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td width=20%></td> <td width=20%> <table height=120 border=0 cellspacin +g=0 align=center cellpadding=5> <tr> <td align=left > <span class="Menue">User Name:</sp +an> </td> </tr> <tr> <td align=left > <span class="Menue">Password:</spa +n> </td> </tr> <tr> <td >&nbsp; <input type="hidden" name="destinat +ion" value="../dashboard/homepage.php"> <input type="hidden" name="referer" + value="../dashboard/homepage.php"> <input type="hidden" name="change_p +wd" id="change_pwd"> </td> </tr> </table> </td> <td width=40%> <table width=100% height=120 border +="0" cellspacing="0" cellpadding="5" align="left"> <tr> <td align=right> <input type="text" name="user_ +name_tmp" id="user_name_tmp" style="width: 225px"> </td> </tr> <tr> <input type="hidden" name="passwo +rd_tmp" id="password_tmp"> <td align=right> <input type="password" onChange +="sha1_password();" onMousemove="sha1_password();" id="password_tmp_w +idget" name="password_tmp_widget" style="width: 225px"> </td> </tr> <tr> <td align=right> <input type="submit" class="UCD" on +click="login();" value='&nbsp;Login&nbsp;'</input> </td> </tr> </table> </td> <td width=20%></td> </tr> </table> </tr> <tr height=50><td></td></tr> <tr> <td width=600 height=5 colspan=3 bgcolor="FF +CC00"></td> </tr> </table> </td> </tr> </form> </table> <p>&nbsp;</p> </td> </tr> </table> </body> </html>

In reply to testing website with login by edwardt_tril

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.