Test::LWP::Recorder - Create an LWP UserAgent that records and plays back sessions
This document describes v0.1.0 of Test::LWP::Recorder - released June 07, 2011 as part of Test-LWP-Recorder.
use Test::LWP::Recorder; my $ua = Test::LWP::Recorder->new({ record => $ENV{LWP_RECORD}, cache_dir => 't/LWPCache', filter_params => [qw(api_key api_secret password ssn)], filter_header => [qw(Client-Peer Expires Client-Date Cache-Control)], });
This module creates a LWP UserAgent that records interactions to a test drive. Setting the "record" parameter to true will cause it to record, otherwise it plays back. It is designed for use in test suites.
In the case that a page is requested while in playback mode that was not recorded while in record mode, a 404 will be returned.
There is another module that does basically the same thing called LWPx::Record::DataSection. Please check this out before using this module. It doesn't require a special UA, and stores the data in the DATA section of your file. I use this module (a copy in inc/) for my test suite!
This creates a new object. Please see PARAMETERS for more details on available options.
The returned object can be used just like any other LWP UserAgent object.
This is overridden from LWP::UserAgent so we can do our magic.
Setting this to true puts the agent in record mode. False, in playback. You usually want to set this to an environment variable.
This is the location to store the recordings. Filenames are all MD5 digests.
This is an ArrayRef of POST or GET parameters to remove when recording.
The default for this is no filtering.
For example (using the $ua created in the synopsis):
# This is the request my $resp = $ua->get('http://www.mybank.com?password=IAMSOCOOL&ssn=111-11-1111&method=transfer&destination=CH'); # Because password and ssn are filtered, these parameters will be removed # from the object stored. If a tester in the future makes the following # call: # my $resp = $ua->get('http://www.mybank.com?password=GUESSME&ssn=999-11-9999&method=transfer&destination=CH'); The cache result from the first will be used.
A list of response headers not stored.
Default is [qw(Client-Peer Expires Client-Date Cache-Control)];
A page was requested while in playback mode that was not recorded in record mode. A 404 object will be returned.
Please note that you should <b>always</b> put this in an inc directory in your module when using it as part of a test suite. This is critical because the filenames in the cache may change as new features are added to the module.
Feel free to just copy the module file over and include it in your inc (provided that your module uses Perl5, GPL, or Artistic license). If you make any changes to it, please change the version number (the last number).
Thanks to motemen for LWPx::Record::DataSection which I use to test this module (and bundle in the inc/ directory). It's a great module and a simple approach.
This works using a new UserAgent, which may not work for you.
Currently Cookies are ignored.
The filename scheme is pretty lame.
The test suite needs to be extended to include a POST example
Please see those modules/websites for more information related to this module.
LWP::UserAgent
LWPx::Record::DataSection
The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
Search CPAN
The default CPAN search engine, useful to view POD in HTML format.
http://search.cpan.org/dist/Test-LWP-Recorder
CPAN Testers Dependencies
The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
http://deps.cpantesters.org/?module=Test::LWP::Recorder
CPANTS
The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
http://cpants.perl.org/dist/overview/Test-LWP-Recorder
CPAN Testers
The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.
http://www.cpantesters.org/distro/T/Test-LWP-Recorder
CPAN Testers Matrix
The CPAN Testers Matrix is a website that provides a visual way to determine what Perls/platforms PASSed for a distribution.
http://matrix.cpantesters.org/?dist=Test-LWP-Recorder
You can email the author of this module at EALLENIII at cpan.org asking for help with any problems you have.
EALLENIII at cpan.org
Please report any bugs or feature requests by email to bug-test-lwp-recorder at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-LWP-Recorder. You will be automatically notified of any progress on the request by the system.
bug-test-lwp-recorder at rt.cpan.org
The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)
http://github.com/riemann42/Test-LWP-Recorder
git clone git://github.com/riemann42/Test-LWP-Recorder.git
Edward Allen <ealleniii@cpan.org>
This software is copyright (c) 2011 by Edward J. Allen III.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
To install Test::LWP::Recorder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::LWP::Recorder
CPAN shell
perl -MCPAN -e shell install Test::LWP::Recorder
For more information on module installation, please visit the detailed CPAN module installation guide.