Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am trying to write some UI tests for a web app using WWW::Mechanize. I have however run into a snag while writing tests to handle some edge cases. I am trying to make sure my backend code can handle an enduser messing with radio button values (ie saving the form, changing the radio button values and re-submitting).

While writing these tests I found out that I can not submit a form using WWW::Mechanize with an invalid entry entered into a radio button field. WWW::Mechanize uses the HTML::Form module to handle form parsing/filling/submitting, and that module happens to be very strict about the values you can assign to a field that is a radio button (or a select box for that matter)...

Has anyone run into this before? Is there a clean solution? Did I miss something obvious?

A quick example of what I am trying follows:

use Test::More qw(no_plan); use Test::HTML::Lint; use WWW::Mechanize; my $a = WWW::Mechanize->new(); $a->get( $url ); is( $a->status, 200, 'Fetched OK' ); like( $a->content, qr/Details/, "Correct page"); html_ok( $a->content, "Details HTML" ); $a->form_name('details'); $a->field( a_radio_button => 'invalid_value' ); # <-- dies here $a->click();

The above code will fail and die at the call to $a->field(...). I have tried making calls directly to the HTML::Form object to no avail, but it looks like according to the perldocs for HTML::Form that it is working exactly as advertized. Is there another way to do what I want?

Update:I was silly for not including the error message I got. HTML::Form is doing exactly what is advertized in the docs. It will die with an error message when an bad value is assigned to a radio button or select box. I am looking for another way of doing the same thing (ie using something besides HTML::Form to build a request object, or convincing HTML::Form to accept a bad value...)

The error message HTML::Form spits out is as follows: Illegal value 'invalid_value' for field 'a_radio_button' at /usr/local/share/perl/5.8.2/HTML/Form.pm line 426

- Cees


In reply to HTTP::Form and invalid radio button values by cees

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2019-12-13 00:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?