HTTP::RecordedSession - Class to interface with serialized clicks from Apache::Recorder
Two sample scripts are provided below: one for HTTP::Monkeywrench, and one for HTTP::WebTest.
###################### Monkeywrench #####################
use strict;
use HTTP::RecordedSession;
use HTTP::Monkeywrench;
my ( $config_id ) = '1WFmxpCj'; #ID from recorder.pl
my ( $conf ) = new HTTP::RecordedSession( config_id => $config_id, path => "/usr/tmp/", # optional test_mod => "Monkeywrench", # optional );
my ( $clicks ) = $conf->get_clicks;
my ( %settings ) = ( #See Monkeywrench docs show_cookies => '1', print_results => '1', );
my ( $wrench ) = HTTP::Monkeywrench->new( \%settings );
$wrench->test( $clicks );
###################### WebTest #########################
use HTTP::WebTest qw( run_web_test );
my ( $conf ) = new HTTP::RecordedSession( config_id => $config_id, path => "/usr/tmp/", # optional test_mod => "WebTest", # optional );
my ( %options ) = ( #See WebTest docs show_cookies => 'yes', terse => 'summary', );
my ( $num_fail, $num_succeed );
my ( $results ) = run_web_test($clicks, \$num_fail, \$num_succeed, \%options);
#######################
HTTP::RecordedSession will correctly format the output of Apache::Recorder for a script that uses either HTTP::Monkeywrench or HTTP::WebTest.
The HTTP::RecordedSession::new() method accepts a hashref with three possible elements:
config_id: This is the id provided by recorder.pl when you first begin recording an HTTP session. This element is required.
path: This is intended to provide greater portability -- you do not have to use the (Linux-based) default path of "/usr/tmp/", although RecordedSession will default to this to ensure backwards compatibility if no path is provided.
test_mod: This option allows you to choose between HTTP:: Monkeywrench and HTTP::WebTest to actually test your recorded session. HTTP::RecordedSession will default to 'Monkeywrench' to ensure backwards compatibility.
There are only three public methods:
new()
get_clicks: this method returns the clicks formatted for either HTTP::Monkeywrench or HTTP::WebTest.
get_id: this method returns the config_id that is passed to the HTTP::RecordedSession constructor.
Scripts that were written using HTTP::RecordedSession version 0.03 are not compatible out of the box with scripts written using version 0.04. The $self->get_clicks method returned an arrayref to an arrayref of hashrefs in version 0.03. This has been fixed in version 0.04, so that $self->get_clicks returns a simple arrayref of hashrefs. In terms of code, you need to change:
my ( $clicks ) = @{ $conf->get_clicks };
to:
Apologies for the inconvenience.
By default HTTP::RecordedSession sets the acceptcookie / sendcookie (Monkeywrench) and accept_cookies / send_cookies (WebTest) parameters to 1 and yes respectively. You can change this behavior for the entire test in the %options hash. However, if you only want to change it for a subset of the clicks in $clicks, you will (at present) need to loop through the clicks and set them by hand.
Chris Brooks <cbrooks@organiccodefarm.com>
Apache::Recorder
HTTP::Monkeywrench
HTTP::WebTest
To install HTTP::RecordedSession, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::RecordedSession
CPAN shell
perl -MCPAN -e shell install HTTP::RecordedSession
For more information on module installation, please visit the detailed CPAN module installation guide.