Automatically Testing a Form
By Randal L. Schwartz
I've written quite a few CGI programs to handle form data. I'm always interested in finding ways to test these form handlers, especially ways to invoke them with canned or computed data, or even to stress test them.
Of course, it's easy to write a Perl program that invokes a CGI script to handle computed form data. You just whip out LWP, add a dabble of HTTP::Request::Common, figure out what you want the form to be filled with, write the code, and you're done.
But what if there are many fields, or you didn't write the form yourself and you're having trouble scanning through the HTML source code to get all the form input fieldnames and default values? Well, Perl can help with that, too. After all, we can parse HTML and generate Perl programs with Perl programs. What if we wrote a Perl program to invoke the URL of the form page, study the resulting HTML, and come up with another Perl program that invokes the resulting form action script? Well, that doesn't have to be a "what if," because such a program is presented in
Listing One.
Lines 1 through 3 enable warnings, common compiler restrictions, and disable buffering on STDOUT, letting us see output as it occurs.
Lines 5 through 9 bring in five modules from the LWP library, found in the CPAN (at
|