Using YAML to speed up creating WWW::Mechanize test scripts

markjugg on 2006-06-29T19:58:46

Test::WWW::Mechanize is a great web testing tool, but typing out the name/value pairs of a long form is no fun, at least when done in Perl hash syntax.

Today I experimented with using YAML to help with. YAML is more human friendly for data entry in that it doesn't usually need quoting, and the end-of-line-comma can be omitted.

Here's how I got two great tastes to test great together:

use YAML::Syck;
$mech->submit_form(
        fields => Load(q{
          first_name          : Mark
          last_name           : Stosberg
          street_address      : 211 NW I ST
          # ... lots more data... 
}));

I further sped-up the process by using the 'mech-dump' give me the field names in the first place, which I copied in here. (This step only helps if you are sure you have the right fields on the form in the first place!).

With a little work, mech-dump could output YAML directly, making for a smooth round-trip workflow.