Re: Testing my CGI

[email protected] (John SJ Anderson) Tue, 4 Nov 2014 10:29:09 -0800
Newsgroups perl.beginners.cgi
Message-ID <CABJ3DF8UOO0SG8QU3eLo0q2AuJ=LW4+gyLnkEZhEsXEQC0FWzw@mail.gmail.com>
Look at the source code for the module. The 'tick' method just uses a
bare 'return' on success, which means it's going to fail an ok() test
regardless of whether or not it works.

You may also want to look at Test::WWW::Mechanize.

chrs,
john.


On Tue, Nov 4, 2014 at 7:30 AM, Patton, Billy N <[email protected]> wr=
ote:
> I=E2=80=99m using WWW::Mechanize for testing my CGI.
> I=E2=80=99m having trouble with the $mech->tick
>
> Here=E2=80=99s my code :
>   ok($mech->form_name('cdr_format'),"getting form cdr_format");
> print "pAllFields =3D " . $mech->value('pAllFields') . "\n";
> 219->  ok($mech->tick('pAllFields',1), 'Setting checkbox to native CDR fo=
rmat');
> 220->  ok($mech->tick('pAllFields=E2=80=99,0), 'Setting checkbox to nativ=
e CDR format=E2=80=99);
>
>
>
> Here=E2=80=99s a snippet of the html :
> <div id=3D'myForm'>
>         <form name=3D'cdr_format' method=3D'POST' action=3D'file_admin.cg=
i'>
>         <input type=3D'hidden' name=3D'rm' value=3D'process_cdr_format'>
>         <input type=3D'hidden' name=3D'CGISESSID' value=3D'ec4c3463d5a7f9=
d04d2924968413f240'>
>         <input type=3D'hidden' name=3D'cdr_format' value=3D'1'>
>         <table border=3D'0' cellpadding=3D'3' cellspacing=3D'0' width=3D'=
100%'>
>         <tr>
>         <td class=3D'fieldLabel' width=3D'60%'>
>         We would like the files in native CDR format:
>         </td>
>         <td class=3D'field'>
>         <input type=3D'checkbox' class=3D'checkbox' name=3D'pAllFields' v=
alue=3D'1'>
>
>         </td>
>         </tr>
>
>
> When I execute I get this :
> ok 40 - getting form cdr_format
> Use of uninitialized value in concatenation (.) or string at ./test_cport=
al.pl line 218.
> pAllFields =3D
> not ok 41 - Setting checkbox to native CDR format
> #   Failed test 'Setting checkbox to native CDR format'
> #   at ./test_cportal.pl line 219.
> not ok 42 - Setting checkbox to native CDR format
> #   Failed test 'Setting checkbox to native CDR format'
> #   at ./test_cportal.pl line 220.
>
> Here=E2=80=99s the documentation from WWW::Mechanize
> $mech->tick( $name, $value [, $set] )
>
> "Ticks" the first checkbox that has both the name and value associated wi=
th it on the current form. Dies if there is no named check box for that val=
ue. Passing in a false value as the third optional argument will cause the =
checkbox to be unticked.