HTTP::WebTest::XMLParser - Parse wtscript in XML representation.
use HTTP::WebTest::XMLParser; my ($tests, $opts) = HTTP::WebTest::XMLParser->parse($xmldata); use HTTP::WebTest; my $wt = new HTTP::WebTest; $wt->run_tests($tests, $opts); HTTP::WebTest::XMLParser->as_xml($tests, $opts, { nocode => 1 });
Parses a wtscript file in XML format and converts it to a set of test objects.
$Revision: $
The xml format follows wtscript closely, with the following rules:
- the root element is <WebTest/> - global paramters are in a <params/> element - test definitions are in <test/> elements - a list is represented by a <list/> element - a scalar param. is represented by a <param/> element - a code segment is represented by a <code/> element - named parameters are named throug a 'name' attribute
The DTD is available in 'scripts/webtest.dtd' from the distribition. For examples see the test definitions in t/*xml from the distribution.
A conversion script from wtscript to XML is available in 'scripts/testconversion' from the distribution. This script also converts XML definitions from earlier alpha versions of this module.
This example is the equivalent of the same example for HTTP::WebTest
The definition of tests and params from the original example:
my $tests = [ { test_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 $params = { mail_server => 'mailhost.mycompany.com', mail_addresses => [ 'tester@mycompany.com' ], mail => 'all', ignore_case => 'yes', };
This Perl script tests Yahoo home page and sends full test report to "tester@mycompany.com".
use HTTP::WebTest; use HTTP::WebTest::XMLParser; my $XML = <<"EOXML"; <WebTest version="1.0"> <params> <param name="ignore_case">yes</param> <list name="mail_addresses"> <param>tester@mycompany.com</param> </list> <param name="mail_server">mailhost.mycompany.com</param> <param name="mail">all</param> </params> <test> <param name="min_bytes">13000</param> <param name="max_bytes">99000</param> <param name="url">http://www.yahoo.com</param> <param name="test_name">Yahoo home page</param> <list name="text_require"> <param><![CDATA[<a href=r/qt>Quotations</a>...<br>]]></param> </list> </test> </WebTest> EOXML my ($tests, $params) = HTTP::WebTest::XMLParser->parse($XML); my $webtest = new HTTP::WebTest; $webtest->run_tests($tests, $params);
Parses wtscript in XML format passed in $xmldata as string.
$xmldata
A list of two elements - a reference to an array that contains test objects and a reference to a hash that contains test parameters.
Given a set of test parameters and global parameters, returns the XML representation of the test script as a string.
The test definitions and parameters can be obtained from plain wtscript as parsed by HTTP::WebTest::Parser.
wtscript
Forces the replacement of CODE sections by dummy subroutines. Example:
CODE
$xml = HTTP::WebTest::XMLParser->as_xml( $tests, $param, { nocode => 1 } );
The test defintion in XML format.
Any CODE references in the test object will be replaced by a dummy subroutine if B::Deparse is missing from your installation. In order to make this more predictable, you can force this behaviour by specifying option nocode.
nocode
Lists of named parameters are internally stored as array with an even number of elements, rather than a hash. This has the purpose of preserving order of the parameters and also allow more than one parameter with the same name. When such a list is serialized back into XML, the list element contains a list of anonymous parameters, one for each key and value.
Original test definition:
<list name="http_headers"> <param name="Accept">text/html,application/xml+html</param> <param name="Accept-Encoding">deflate,gzip</param> </list>
Output as:
<list name="http_headers"> <param>Accept</param> <param>text/html,application/xml+html</param> <param>Accept-Encoding</param> <param>deflate,gzip</param> </list>
Both versions are functionally equivalent (just like ',' and '=>' notation are equivalent for Perl hashes).
Copyright (c) 2002 - 2003 Johannes la Poutre. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTTP::WebTest
HTTP::WebTest::Parser
HTTP::WebTest::API
Examples are in directory 't' from the distribution, the DTD and utility scripts are in subdir 'scripts' from the distribution.
To install HTTP::WebTest::XMLParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::WebTest::XMLParser
CPAN shell
perl -MCPAN -e shell install HTTP::WebTest::XMLParser
For more information on module installation, please visit the detailed CPAN module installation guide.