NAME

HTTP::WebTest::Reference - HTTP::WebTest reference.

SYNOPSIS

Not applicable.

DESCRIPTION

This document describes:

TEST SPECIFICATION

The test specifications can be read from a parameter file (wtscript) or input in form of array of hashes.

Wtscript

HTTP::WebTest can read test specification from file in format called as wtscript. Tests defined by wtscript file can be run either using Perl API of HTTP::WebTest

use HTTP::WebTest;

my $webtest = new HTTP::WebTest;
$webtest->run_wtscript('script.wt');

or by using program wt supplied with this module.

File format

The following is ignored in wtscript file:

  • lines consisting of nothing but white space (blanks or tabs)

  • lines beginning with a number sign (#)

  • lines beginning with white space (blanks or tabs) followed by a number sign

The order of the parameters in the parameter file is arbitrary, with the following exceptions:

  • Test block parameters MUST occur between a test_name parameter and an end_test directive.

  • Global parameters must NOT occur between a test_name parameter and an end_test directive. (This requirement does not apply to parameters that are both global and test block parameters.)

Parameters are either scalar (single-valued) or lists (single or multi-valued).

You can specify scalar parameters using forms such as:

name = value
name =
       value
name = 'value'

You can specify list parameters using forms such as:

name = ( first value
         second value )
name = ( first value => second value
         third value => fourth value
       )
name = ( first value => second value )
name = (
         'first value'
         'second value' )
name = (
         first value
         second value
         third value => 'fourth value'
       )
name =
       ( first value
         'second value' )
name = (
         'first value'
         'second value'
       )

(The equals sign must be followed by a space, tab or newline; all other spaces are optional.)

PARAMETER VALUES BEGINNING AND ENDING WITH A SINGLE QUOTE WILL HAVE THE SINGLE QUOTES REMOVED. For example, 'foobar' is parsed as a value of foobar and ''foobar'' is parsed as a value of 'foobar'. To specify a null (placeholder) value, use ''.

You MUST enclose the parameter value in single quotes if you want to specify:

  • a value beginning with a left parenthesis

  • a value ending with a right parenthesis

  • a value beginning with leading white space (blanks or tabs)

  • a value ending with trailing white space (blanks or tabs)

  • a value beginning and ending with single quotes

Examples of wtscript files

The parameters below specify tests of a local file and a remote URL. The tests specified by the text_forbid parameter apply to both the "RayCosoft home page" and the "Yahoo home page" tests. Hence, if either returned page contains one of the case-insensitive strings in text_forbid, the test fails. If any test fails or the fetch of the URL fails, an e-mail will be sent to tester@unixscripts.com.

apache_exec = /usr/sbin/apache
ignore_case = yes
mail = errors
mail_addresses = ( tester@unixscripts.com )
mail_server = mailhost.unixscripts.com
text_forbid = ( Premature end of script headers
                an error occurred while processing this directive
              )

test_name = 'RayCosoft home page (static)'
    file_path = ( raycosoft_home.html => . )
    text_require = (
        <a href="/dept/peopledev/new_employee/"><font color="#0033cc">
        <a href="https://www.raycosoft.com/"><font color=
                   )
end_test

test_name = Yahoo home page
    url = www.yahoo.com
    text_require = ( <a href=r/qt>Quotations</a>...<br> )
    min_bytes = 13000
    max_bytes = 99000
    min_rtime = 0.010
    max_rtime = 30.0
end_test

The parameters below specify a test of a local file containing Perl code using the Apache::ASP module. The includes.htm file requires five include files and two Perl modules, which are copied using the include_file_path parameter.

apache_exec = /usr/sbin/apache
ignore_case = yes
include_file_path = ( footer.inc => htdocs/apps/myapp/inc
                      header.inc => htdocs/apps/myapp/inc
                      head.inc   => htdocs/apps/myapp/inc
                      go.script  => htdocs/shared/includes
                      go.include => htdocs/shared/includes
                      ../utils/DBconn.pm  => lib/perl/utils
                      ../utils/Window.pm  => lib/perl/utils
                    )

test_name = includes.htm
    file_path = ( includes.htm => apps/myapp )
    min_bytes = 33000
    max_bytes = 35000
    text_require = ( input type=hidden name=control value= )
    text_forbid  = ( Premature end of script headers
                     an error occurred while processing this directive
                   )
end_test

Array of Hashes

Each hash in array defines tests for one URL. Keys in hashes are test parameter names and values in hashes are values of test parameters. Also there can be defined global test parameters in form of hash for each test sequence.

Tests can be run as

use HTTP::WebTest;

my $webtest = new HTTP::WebTest;
$webtest->run_tests(
                    [ # test 1
                      { param1 => value1,
                        param2 => value2 },
                      # test 2
                      { param1 => value1,
                        param2 => value2 },
                    ],
                    { global_param1 => value1,
                      global_param2 => value2 }
                   );

Example

This Perl script tests Yahoo home page and sends full test report to tester@unixscripts.com.

use HTTP::WebTest;

my $tests = [
             { name         => 'Yahoo home page',
               url          => 'http://www.yahoo.com',
               text_require => [ '<a href=r/qt>Quotations</a>...<br>' ],
               min_bytes    => 13000,
               max_bytes    => 99000,
             }
            ];
my $options = { mail_server    => 'mailhost.unixscripts.com',
                mail_addresses => [ 'tester@unixscripts.com' ],
                mail           => 'all',
                ignore_case    => 'yes',
              };

$webtest->run_tests($tests, $options);

TEST PARAMETERS

Content of this section should be autogenerated from POD docs in plugin modules.

COPYRIGHT

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.

SEE ALSO

HTTP::WebTest

HTTP::WebTest::Reference

wt