HTTP::WebTest - Test remote URLs or local web files
All HTTP::WebTest API cannot be summarized here. Only basic usage.
use HTTP::WebTest; my $webtest = new HTTP::WebTest; $webtest->run_wtscript('script.wt'); $webtest->run_tests($tests);
See below for all API.
This module runs tests on remote URLs or local web files containing Perl/JSP/HTML/JavaScript/etc. and generates a detailed test report. This module has plugin based architecture. Plugins can define test types and provide various report capabilities. This module comes with a set of default plugins but can be easily extended with third party plugins.
The test specifications can be read from a parameter file (wtscript) or input as method arguments. If you are testing a local file, Apache is started on a private/dynamic port with a configuration file in a temporary directory. The module can display the test results via report plugin(s). Default report plugin can output them on the terminal, directs them to a file or scalar variable and/or email them.
Data flow for HTTP::WebTest using a remote URL:
HTTP::WebTest
-------------- ------------- | | | | | Input |------------->| WebTest | | parameters | | | | | ------------- -------------- | ^ | | V | ------------- ------------ | | request | | | Remote |<--------------| HTTP | | webserver |-------------->| user | | | response | agent | ------------- | | ------------
Data flow diagram for HTTP::WebTest using a local web file:
-------------- --------------------- | | | | | Input | | Web page code | | parameters | | (Perl/HTML/etc.) | | | | | -------------- --------------------- | | | --------------------------- | | V V ------------------------ ------------- | | | |---------->| Temporary Apache | | WebTest | | directories (htdocs, | | |<----------| conf, logs) | ------------- | | | ^ ------------------------ | | | ^ V | V | ------------ ---------------------- | | request | | | HTTP |------------>| Temporary local | | user | | instance of Apache | | agent |<------------| | | | response ---------------------- ------------
If you are new to HTTP::WebTest 2.xx you should read:
HTTP::WebTest 2.xx
perldoc HTTP::WebTest::Reference - description of test specification, list of test types and reports provided by default plugins.
perldoc HTTP::WebTest::Cookbook - examples of wtscript files and example of HTTP::WebTest API usage.
perldoc HTTP::WebTest::Plugins - for developers of HTTP::WebTest plugins.
Those documents cover basic usage of HTTP::WebTest. This document describes Perl API of HTTP::WebTest.
Constructor.
A new HTTP::WebTest object.
A reference on array which contains test objects.
Can switch user agent used by HTTP::WebTest object if $optional_user_agent is a user agent object. If it is passed as undef resets HTTP::WebTest object to use default user agent.
$optional_user_agent
An user agent object used by HTTP::WebTest object.
Can set plugins to be used during tests if $optional_plugins is a reference on array which contains plugin objects. If it is passed as undef resets HTTP::WebTest object to use default set of plugins.
$optional_plugins
A reference on array which contains plugin objects. Note that if you add or remove plugin objects to this array it will change set of plugins used by HTTP::WebTest object during tests.
A new default user agent.
Resets user agent to default.
Resets set of plugin objects to default.
A reference on set of default plugin objects.
A value of global test sequence parameter $param.
$param
A test object which corresponds to last test being or been run.
A request object used in last test.
A response object returned for last request.
A response time for last request.
A reference on array which contains results of checks made by plugins for last test.
Runs single test.
$test
A test object.
$optional_params
A reference on hash which contains optional global parameters for test.
Runs a test sequence.
Converts test objects @tests of any supported type to canonic representation (i.e. to HTTP::WebTest::Test objects).
@tests
A list of HTTP::WebTest::Test objects in list context or first value from list of HTTP::WebTest::Test object in scalar context.
Validates test.
A hash with results of checks.
Parses wtscript passed in scalar variable $data.
A reference on an array which contains test objects.
Reads wtscript and runs tests it defines.
$file
A filename of wtscript file.
A reference on hash which contains optional test parameters which can override parameters defined in wtscript.
A number of failed tests.
A number of passed tests.
True if all tests have been passed.
HTTP::WebTest 2.xx offers more rich API than its predecessor HTTP::WebTest 1.xx. However while deprecated old API is still supported.
HTTP::WebTest 1.xx
It is not recommended to use it in new applications.
In HTTP::WebTest 2.xx you should use method run_wtscript.
run_wtscript
$num_fail_ref
A reference on scalar where a number of failed tests will be stored or undef if you don't need it.
undef
$num_succed_ref
A reference on scalar where a number of passed tests will be stored or undef if you don't need it.
This is not a method. It is subroutine which creates a HTTP::WebTest object and runs test sequence using it.
You need either import run_web_test into you namespace with
run_web_test
use HTTP::WebTest qw(run_web_test);
or use full name HTTP::WebTest::run_web_test
HTTP::WebTest::run_web_test
In HTTP::WebTest 2.xx you should use method run_tests.
run_tests
$tests
A reference on array which contains a set of test objects.
A reference on hash which contains optional test parameters.
This module have been tested only on Unix (e.g., Solaris, Linux, AIX, etc.) but it should work on Win32 systems.
Local file tests don't work on Win32 systems.
The module's HTTP requests time out after 3 minutes (the default value for LWP::UserAgent). If the file_path parameter is specified, Apache must be installed.
Richard Anderson <Richard.Anderson@unixscripts.com> have wrote HTTP::WebTest 1.xx.
Ilya Martynov <ilya@martynov.org> made rewrite of HTTP::WebTest. He is maintaining HTTP::WebTest now. Please email him bug reports, suggestions, questions, etc.
Copyright (c) 2000-2001 Richard Anderson. All rights reserved.
Copyright (c) 2001,2002 Ilya Martynov. All rights reserved.
This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License.
HTTP::WebTest::Reference
HTTP::WebTest::Plugins
wt
To install HTTP::WebTest, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::WebTest
CPAN shell
perl -MCPAN -e shell install HTTP::WebTest
For more information on module installation, please visit the detailed CPAN module installation guide.