Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have a large number of tests to write that use WWW::Mechanize to test web page sequences. These sequences are exercized by filling in form variables and POSTing. The values of form variables, along with other variables determine what the next page in the sequence will be and can also cause data to be shown or suppressed on later pages.

In writing these tests, I've been migrating to a data-driven structure like the code below. This has factored out some of the repetitive code, but I think there is room for further improvement. My goal is to end up with test scripts that are largely self-documenting in terms of what actions are being performed and what results are being tested and that have little repeated code.

Does anyone see a different approach that would be a better fit? Does anyone have any useful references on data-driven programming in perl? I have turned up very little with google and super-search.

... my $mech = WWW::Mechanize->new(...); my $question = { 1 => 'value_12345', 2 => 'value_12346', 3 => 'value_12347', }; my $test_list = [ { name => 'First page of sequence', check_list => [ # Things to compare content to on this page [ qr/Some text/, "test name" ], ], action => sub { # Action to perform from this page $mech->click; }, }, { name => 'page seen after first click', check_list => [ [ qr/Dst1/, "destination1" ], ], action => sub { $mech->submit_form( fields => { $question->{1} => 3, # Q1, choice 3 (radio button) }); }, }, { name => 'page seen after second POST', check_list => [ [ qr/Dst2/, "destination2" ], [ qr/more text/, "more text expected on this page" ], ], action => sub { $mech->submit_form( fields => { $mech->back; $mech->back; }); }, }, ]; $mech->get(qq[some_uri]); my $verbose = 0; for my $test(@$test_list) { my $name = $test->{name}; my $check_list = $test->{check_list}; for my $check(@$check_list) { like($mech->content, $check->[0], "test $name - $check->[1]"); } diag $mech->current_form->dump if $verbose; if ($test->{action}) { $test->{action}->(); } sleep 1; # Optional }

In reply to Data-driven programming with WWW::Mechanize by mp

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 scrutinizing the Monastery: (5)
As of 2024-04-19 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found