HTTP::Recorder and WWW::Mechanize for testing web sites

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

WWW::Mechanize is a Perl module that simulates a web browser.
You can use HTTP::Recorder to write WWW::Mechanize code automatically as
you surf, see the article:

Then you can improve this code with variables and loops and use it for
testing of web sites.

I saved the proxy server program in the article and started it:
./ &

I reconfigured Firefox to use the proxy server in
Preferences/Advanced/Network/Connection Settings. It's on port 8080 on
localhost, and use this for all protocols. Remember to remove localhost
and from 'No Proxy for' if you test against a local web server.

Then I test my web application using a newly reseted test database.

After that I stop the proxy:
kill -15 %1

And reset the database.

I then edit the file with output from the proxy script and add at top:
use strict;
use warnings;
use WWW::Mechanize;
# use Test::More qw(no_plan);
my $agent = WWW::Mechanize->new();

I run this program. This should run without errors.

I can also check my web application and see that it is in the state it
should be.

Now I have a test script that I can use after major changes to the web
application to test that everything is still working.

Hidden form fields are considered read-only by HTTP::Recorder and
WWW::Mechanize. I sometimes change them from JavaScript. I solved this
by making them type="text" and setting the style="display:none".

There is a bug in 0.05 of HTTP::Recorder that bothered me but it can be
fixed, see:

// Mikael

Site Timeline