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


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          => '',
                   text_require => [ '<a href=r/qt>Quotations</a>...<br>' ],
                   min_bytes    => 13000,
                   max_bytes    => 99000,
  my $params = { mail_server    => '',
                 mail_addresses => [ '' ],
                 mail           => 'all',
                 ignore_case    => 'yes',

This Perl script tests Yahoo home page and sends full test report to "".

 use HTTP::WebTest;
 use HTTP::WebTest::XMLParser;
 my $XML = <<"EOXML";
 <WebTest version="1.0"> 
    <param name="ignore_case">yes</param>
    <list name="mail_addresses">
    <param name="mail_server"></param>
    <param name="mail">all</param>
    <param name="min_bytes">13000</param>
    <param name="max_bytes">99000</param>
    <param name="url"></param>
    <param name="test_name">Yahoo home page</param>
    <list name="text_require">
      <param><![CDATA[<a href=r/qt>Quotations</a>...<br>]]></param>
 my ($tests, $params) = HTTP::WebTest::XMLParser->parse($XML);

 my $webtest = new HTTP::WebTest;
 $webtest->run_tests($tests, $params);


parse ($xmldata)

Parses wtscript in XML format passed in $xmldata as string.


A list of two elements - a reference to an array that contains test objects and a reference to a hash that contains test parameters.

as_xml ($tests, $params, $opts)

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.

Option nocode

Forces the replacement of CODE sections by dummy subroutines. Example:

 $xml = HTTP::WebTest::XMLParser->as_xml(
                                         { nocode => 1 }


The test defintion in XML format.


Method as_xml()

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.

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>

Output as:

  <list name="http_headers">

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.





Examples are in directory 't' from the distribution, the DTD and utility scripts are in subdir 'scripts' from the distribution.