Update of /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest
In directory usw-pr-cvs1:/tmp/cvs-serv22604/lib/HTTP/WebTest
Modified Files:
Cookbook.pod
Log Message:
Added ::Hooks usage example into cookbook
Index: Cookbook.pod
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Cookbook.pod,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Cookbook.pod 30 Jan 2002 16:47:13 -0000 1.6
--- Cookbook.pod 16 Feb 2002 00:37:43 -0000 1.7
***************
*** 12,22 ****
usage.
! All examples are either runnable programs (see
! L<HTTP::WebTest::API|HTTP::WebTest::API>) or runnable wtscript files
! (see L<perldoc wt|wt>).
=head1 BASICS
! =head2 Check Statis Website
This wtscript tests couple of static pages on my website:
--- 12,22 ----
usage.
! Unless otherwise is stated all examples are either runnable programs
! (see L<HTTP::WebTest::API|HTTP::WebTest::API>) or runnable wtscript
! files (see L<perldoc wt|wt>).
=head1 BASICS
! =head2 Check Static Website
This wtscript tests couple of static pages on my website:
***************
*** 84,88 ****
=head1 ADVANCED
! =head2 Test::Harness compatible output
This Perl script reads test specification from file C<test.wt> and
--- 84,88 ----
=head1 ADVANCED
! =head2 Test::Harness Compatible Output
This Perl script reads test specification from file C<test.wt> and
***************
*** 97,100 ****
--- 97,174 ----
plugins => [ '::HarnessReport' ]
});
+
+ =head2 User-Defined Checks
+
+ It is possible to define new checks without writting new plugin
+ module. Here fragment of wtscript file which checks if a new record
+ have been inserted into a database as result of test request.
+
+ # load HTTP::WebTest::Plugin::Hooks module which provides test
+ # parameter on_response
+ plugins = ( ::Hooks )
+
+ ....
+
+ test_name = Add Record
+ # request to this URL with parameter 'name' adds new record
+ url = http://some.server/add-record
+ params = ( name => 'John' )
+
+ # define check
+ on_response = {
+ # it is assumed that $Test::dbh is database handler
+ my $has_record = $Test::dbh->selectrow_array(
+ 'SELECT COUNT(*) FROM USERS ' .
+ 'WHERE NAME = ?',
+ undef, 'John'
+ );
+
+ # return result of check with a comment
+ [ $has_record > 0 ? 'yes' : 'no', 'Have got John' ];
+ }
+ end_test
+
+ =head2 Dynamic Tests
+
+ Sometimes it is needed to feed the results of a previous test into the
+ next test. For example, C<Add Record> creates a database record, emits
+ HTML containing the new record id, and C<Delete Record> deletes the
+ database record using the record id generated in C<Add Record>.
+
+ It is possible to use L<HTTP::WebTest|HTTP::WebTest> to write such
+ tests. Here incomplete example of wtscript which implements it.
+
+ # load HTTP::WebTest::Plugin::Hooks module which provides test
+ # parameter on_response
+ plugins = ( ::Hooks )
+
+ ....
+
+ test_name = Add Record
+ # request to this URL with parameter 'name' adds new record
+ url = http://some.server/add-record
+ params = ( name => 'John' )
+
+ # get ID from a page
+ on_response = {
+ # get webtest object
+ my $webtest = shift;
+
+ # find ID in the returned page
+ ($ID) = $webtest->last_response->content =~ /ID=(\d+)/;
+
+ # because this sub does no checks returns reference on
+ # empty array
+ [];
+ }
+ end_test
+
+ ....
+
+ test_name = Delete Record
+ # request to this URL with parameter 'id' deletes record
+ url = http://some.server/delete-record
+ params = ( id => { $ID } )
+ end_test
=head1 COPYRIGHT
|