Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-24 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found