HTTP::WebTest::Plugins - Plugin developers documentation.
Not applicable.
This document is good starting point for developers who wish to extend HTTP::WebTest functionality with external plugins.
Plugin can be used to add new test types and add new report types. Plugin is just a Perl package which defines class with a number of methods which if present are called by HTTP::WebTest at various stages of test.
Each plugin package should subclass HTTP::WebTest::Plugin. Report plugins can subclass HTTP::WebTest::ReportPlugin which is subclass of HTTP::WebTest::Plugin instead of it. HTTP::WebTest::ReportPlugin defines some helper methods useful in report plugin and handles some test parameters common for report plugins.
Each plugin package should provide following method:
A hash reference on hash which contains information about supported test parameters and their type.
Each test type is defined by method in HTTP::WebTest::Plugin. Type foobar is defined as method check_foobar in this package. See its documentation for list of all check_**** methods which define all known test types.
foobar
check_foobar
check_****
This method is used to validate values of test parameters. If additional checks are required they can be defined in method validate_test. See below.
validate_test
sub param_types { return { qw(ignore_case yesno text_forbid list text_require list regex_forbid list regex_require list) }; }
This is from HTTP::WebTest::Plugin::TextMatchTest. It defines following test parameters: ignore_case, text_forbid, text_require, regex_forbid, regex_require. yesno and list are test parameter types.
ignore_case
text_forbid
text_require
regex_forbid
regex_require
yesno
list
Each plugin package can provide following methods:
This method can be defined in plugin packages to add additional checks for test defined by $test which are not covered by test parameter types specification set by param_types. If you define this method it be sure to call $self-SUPER::validate_test($test)>.
$test
param_types
$self-
This test should return hash with test parameter names as keys and HTTP::WebTest::TestResult objects as values.
This example adds check for test parameter my_test_param. It must be equal to 'BlaBla' if this test parameter is defined.
my_test_param
sub validate_test { my $self = shift; my $test = shift; # run default checks my %checks = $self->SUPER::validate_test($test); if($checks{my_test_param}) { my $ok = $test->param('my_test_param') eq 'BlaBla'; $checks{my_test_param} = $self->test_result($ok, 'Parameter my_test_param is not ' . 'equal to BlaBla'); } return %checks; }
Called before runing test sequence. You can put here some initalization. Report plugins can use this hook to create header of report.
Called when test sequence is finished. You can put here some finialization code. Report plugins can use this hook to finish creation of report.
Called before HTTP::WebTest does HTTP request. Various properties of request here can be set here.
Called once HTTP::WebTest did HTTP request and have got HTTP response. Test checks should be placed here.
Called when HTTP::WebTest got HTTP response after <check_response> hooks. Normally used by report plugins to generate piece of report about test step just done.
This methods should return result of test checks made in following form:
[ [ TEST_GROUP1_NAME, TEST_RESULT1, TEST_RESULT2, ... ], [ TEST_GROUP2_NAME, TEST_RESULT1, TEST_RESULT2, ... ], ... ];
TEST_GROUP_NAME is a string which describes a group of test checks and their results. It is used during generation of test report.
TEST_GROUP_NAME
TEST_RESULT is an HTTP::WebTest::TestResult object.
TEST_RESULT
Well, why anybody need examples when source code of internal HTTP::WebTest plugins is available.
Some good examples are:
Plugin which uses both prepare_request and check_response hooks.
prepare_request
check_response
Very simple plugin which defines only check_response hook.
Example of report plugin. Uses start_tests, report_test and end_tests hooks.
start_tests
report_test
end_tests
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
HTTP::WebTest::API
HTTP::WebTest::Plugin
HTTP::WebTest::ReportPlugin
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.