wst has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am using Test::WWW::Mechanize::Catalyst to test Catalyst form submission. using submit_form_ok, I get "ok" for all possible values of the form (even the wrong values). How does one get test failed on forms? This is what I have.
for (my $mid = 0; $mid < scalar(@mgid); $mid++) { my $message = "Not a valid MGID = $mgid[$mid]\n"; my $message2 = "Found record with MGID = $mgid[$mid]\n"; check_mgtid($mech, $mgt_id[$mid], $message,$baseUrl."/search"); } sub check_mgtid { my ($mech, $mgtid,$message,$searchUrl) = @_; $mech->submit_form($searchUrl, { with_fields => { mgt_id => "$mgtid", }, }, "$message", ); }

Replies are listed 'Best First'.
Re: Catalyst Form test
by Corion (Patriarch) on Apr 28, 2009 at 11:37 UTC
    submit_form_ok only checks whether the page returns a HTTP status code of 200, nothing else. If you return custom messages as error messages, you will have to parse your returned page and check that there is no "message" bar with an error message in it.

      Hi, Looks like I need more help with this one. I am novice to Test::WWW::Mechanize::Catalyst.

      I have a simple search application. First page(and url), asks for one input mgid. If mgid is correct, it will display new page (same url) if mgid is not of correct length/format, an error message is displayed on same page (uses c->flash->{message} format to display error message). if mgid is not found, another chance for checking with shid is given (same url /page but with words SHID : rather than MGID in first instance).

      Can a test be done, to check following:
      1>check if form HTTP status code is 200 (using submit_form_ok for that),
      2> if 1 is ok, then check the page for words /not correct/.
      3> if 2 is not ok then check the page for words /SHID:/
      4> if 3 is not ok, then check page for words /Found/.

      Could such a test be done? Purpose of doing such a test to make sure the flow works for all possible combination. Any suggestion/help would be appreciated.

      Thanks for the quick response, time and help in advance!
        figured it out. thanks!