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

NAME

Test::WWW::Mechanize::Driver - Drive Test::WWW::Mechanize Object Using YAML Configuration Files

SYNOPSIS

 use strict; use warnings;
 use Test::WWW::Mechanize::Driver;
 Test::WWW::Mechanize::Driver->new(
   load => [ glob( "t/*.yaml" ) ]
 )->run;


 use strict; use warnings;
 use Test::WWW::Mechanize::Driver;
 Test::WWW::Mechanize::Driver->new->run; # runs basename($0)*.{yaml.yml,dat}

DESCRIPTION

Write Test::WWW::Mechanize tests in YAML. This module will load the tests make a plan and run the tests. Supports every-page tests, SKIP, TODO, and any object supporting the Test::WWW::Mechanize interface.

This document focuses on the Test::WWW::Mechanize::Driver object and the options it can take. See the Manual for a full description of the test data file format.

USAGE

new

 Test::WWW::Mechanize::Driver->new( [ OPTIONS ] )
add_to_plan

Number of tests running outside of Driver control. Use this option if your test script perfoirms other tests such as build-up of mock objects.

after_response
after_response_tests

after_response is a callback sub triggered once per test group (is not triggered by submit_form_ok or other actions) immediately after the initial response is received. If any tests are run in the callback, the after_response_tests option must be set to the number of tests to be run each time so that the driver may make the proper plan.

base

Base URL for any test uris which are not absolute. If not defined, all test uris must be absolute.

load

Array ref of file names which should be loaded by the Driver. These tests are loaded at object creation time.

loader

Name of loader package or object with package->load( $file ) method. Defaults to Test::WWW::Mechanize::Driver::YAMLLoader.

mechanize

Override default mechanize object. The default object is:

 Test::WWW::Mechanize->new(cookie_jar => {})
no_plan

When true, calling ->run will not print a test plan.

load

 num tests loaded = $tester->load( test filenames )

Load tests.

tests

 num tests = $tester->tests()

Calculate number of tests currently loaded

test_groups

 num groups = $tester->test_groups()

Return number of test groups currently loaded

run

 $tester->run()

Run each group of tests

mechanize

 mech = $tester->mechanize()

Return or construct mechanize object

INTERNAL METHODS

_ensure_plan

 $tester->_ensure_plan()

Feed a plan (expected_tests) to Test::Builder if a plan has not yet been given.

_run_group

 $tester->_run_group( group hash )

Run a group of tests. Performs group-level actions (SKIP, TODO) and tests initial request.

_make_initial_request

 $tester->_make_initial_request( group hash )

Perform initial GET, POST, ... request. Makes after_response callback if present.

_run_test

 $tester->_run_test( group hash, test hash )

Run an individual test. Tests (an action) at theis stage should be in one of the following forms:

 { sub => sub { ... do stuff },
 }

 { name => "mechanize method name",
   args => [ array of method arguments ],
 }

_load

 $tester->_load()

Open test files (listed in @{$$x{load}}) and attempt to load each contained document. Each testfile is loaded only once.

_load_doc

 $tester->_load_doc( any doc, id array )

Determine document type and hand off to appropriate loaders.

_load_group

 $tester->_load_group( non-canonical group hash, id array )

Actually perform test "loading". As test groups are loaded the they are:

 * canonicalized:
     - all tests moved to actions array with one test per entry
     - url misspelling -> uri
     - uri -> $$x{base}/uri if necessary
 * tagged: the test's location in the file is inserted into the test hash

_prepare_actions

 canon-test (actions) array = $x->_prepare_actions( canon-group hash, actions array, group id array )

Prepare array of actions by:

 * expanding aliases
 * expanding tests

_expand_tests

 list of canon-tests = $tester->_expand_tests( canon-group hash, non-canon action item, id array )

Expand a logical action item into possibly many explicit test items. When executed, each test item will increment the test count be exactly 1.

 * prepares argument list

_test_label

 label = $tester->_test_label( group, name, id list )

Convert id components into something human-readable. For example:

 "[description] content_contains: file basic.yml, doc 3, group 5, test 2.b"

_tests_in_group

 $tester->_tests_in_group($group)

Calculates number of tests attributable to the given group. Accounts for initial requerst, explicit actions, and tests in any callbacks.

_autoload

 $tester->_autoload()

Attempt to load test files based on current script name. removes .t or .pl from $0 and globs base*.{yaml,yml,dat}

_clear_local_config

 $tester->_clear_local_config()

Configs local to a series of test documents should be cleared after each file is loaded.

_push_local_config

Merge a new configuration into the local configuration. called for each hash document in a test configuration file.

_apply_local_config

Merge a new configuration into the local configuration. called for each hash document in a test configuration file.

TODO

test and perhaps implement proper enctype="multipart/form-data" file uploads
HEAD, PUT, DELETE requests
Custom Request headers (probably as a "headers" top level hash item so avoid using that as a custom field)

AUTHOR

The original version of this code written by Dean Serenevy while under contract with National Financial Management who graciously allowed me to release it to the public.

 Dean Serenevy
 dean@serenevy.net
 https://serenevy.net/

LICENSE

This software is hereby placed into the public domain. If you use this code, a simple comment in your code giving credit and an email letting me know that you find it useful would be courteous but is not required.

The software is provided "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. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

SEE ALSO

WWW::Mechanize, Test::WWW::Mechanize