The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTTP::WebTest::Plugins - Plugin developers documentation.

SYNOPSIS

Not applicable.

DESCRIPTION

This document is good starting point for developers who wish to extend HTTP::WebTest functionality with external plugins.

ABOUT 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.

REQUIRED METHODS

Each plugin package should provide following method:

param_types

Returns

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.

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.

Example

    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.

OPTIONAL METHODS

Each plugin package can provide following methods:

validate_test ($test)

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)>.

Returns

This test should return hash with test parameter names as keys and HTTP::WebTest::TestResult objects as values.

Example

This example adds check for test parameter my_test_param. It must be equal to 'BlaBla' if this test parameter is defined.

    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;
    }

start_tests

Called before runing test sequence. You can put here some initalization. Report plugins can use this hook to create header of report.

end_tests

Called when test sequence is finished. You can put here some finialization code. Report plugins can use this hook to finish creation of report.

prepare_request

Called before HTTP::WebTest does HTTP request. Various properties of request here can be set here.

check_response

Called once HTTP::WebTest did HTTP request and have got HTTP response. Test checks should be placed here.

report_test

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.

Returns

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_RESULT is an HTTP::WebTest::TestResult object.

EXAMPLES

Well, why anybody need examples when source code of internal HTTP::WebTest plugins is available.

Some good examples are:

HTTP::WebTest::Plugin::Cookies

Plugin which uses both prepare_request and check_response hooks.

HTTP::WebTest::Plugin::StatusTest

Very simple plugin which defines only check_response hook.

HTTP::WebTest::Plugin::DefaultReport

Example of report plugin. Uses start_tests, report_test and end_tests hooks.

COPYRIGHT

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.

SEE ALSO

HTTP::WebTest

HTTP::WebTest::Reference

HTTP::WebTest::Plugin

HTTP::WebTest::ReportPlugin