Creating lengthy programs to test web applications might seem a bit tedious. The mech-dump utility that comes with
WWW::Mechanize prints the names and elements of every form and provides some relief when searching for form and form element names. However, using that data in your tests means that you’ll have to cut and paste multiple small blocks of code. Yuck.
The mech-dump utility that comes with WWW:: Mechanize prints out everything that a WWW:: Mechanize object knows about a web page.
Relieve some of the hassle by using
HTTP::Recorder to set up an HTTP proxy to record the pages you visit and the forms you fill out. As you browse,
HTTP::Recorder saves each action as
Save the following listing as recorder.pl:
At the time of this writing, HTTP::Recorder is incomplete, though it’s still worth using as a base from which you can develop test files for web interaction.
#!perl use strict; use warnings; use HTTP::Recorder; use HTTP::Proxy; my $agent = HTTP::Recorder->new( file => "mech2.t", showwindow => 1 ); my $proxy = HTTP::Proxy->new( port => 4567, agent => $agent, ); $proxy->start();
Next, configure your browser’s proxy settings to connect to your own machine as a proxy on port 4567, as Figure 7-1 shows. Don’t forget to restore the original settings after you finish this lab!
Figure 7-1. Proxy connection ...