O'Reilly logo

Perl Testing: A Developer's Notebook by Chromatic, Ian Langworth

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Record and Play Back Browsing Sessions

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.

Note

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 WWW::Mechanize code.

How do I do that?

Save the following listing as recorder.pl:

Note

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!

Proxy connection settings in Mozilla Firefox

Figure 7-1. Proxy connection ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required