Update of /cvsroot/http-webtest/HTTP-WebTest-Plugin-XMLReport/example
In directory sc8-pr-cvs1:/tmp/cvs-serv19123/example
Added Files:
README testdefs.xml webtest webtest.sh
Log Message:
Added example script for using the XMLReport output
--- NEW FILE: README ---
README XMLReport example script
The scripts and documents in this directory are meant as a demonstration
of how the XMLReport can be used to automate web tests and to enhance
the output of HTTP::WebTest.
For a short demonstration, just run the shellscript 'webtest.sh'
from *this* directory. You need to have Gnome's LibXML installed
and the 'xsltproc' tool somewhere in your PATH.
A short description of the files in this directory:
o webtest - Perl wrapper, parse XML input and call HTTP::WebTest
run 'webtest --help' for a short explanation
o testdefs.xml - Test definitions in XML format, just a bunch of
rather contrieved but nicely annotated examples
o transform/ - a bunch of XSLT stylesheets to convert XMLReport output
o webtest.sha - shell wrapper around 'webtest' and 'xsltproc'
The following files are generated by running webtest.sh:
o out1.xml - output of first test run, XMLReport format
o failed1.xml - test definitions of tests that failed during the
first test run
o out2.xml - otput of second test run
o result.xml - merged result from 1st and 2nd test runs, enhanced
from the XMLReport format (more attributes)
o sidebar.html - summary of test results in html format, suitable for
the Mozilla sidebar
o content.html - detailed report in html format
email.txt - failed test results formatted as email including
headers (suitable to send with sendmail).
Of course this is just a rough example, use your imagination to expand
on this concept!
Feedback and comments are welcome via the HTTP::WebTest site on Sourceforge:
http://sourceforge.net/projects/http-webtest
--- NEW FILE: testdefs.xml ---
<?xml version="1.0" ?>
<!-- root element WebTest
title: describe the purpose of this test suite
-->
<WebTest title="Content tests">
<!-- param element
contains global parameters for HTTP::WebTest and plugins
-->
<param>
<!-- suppress generation of default report -->
<default_report>no</default_report>
<!-- use the following plugins (default prefix is HTTP::WebTest::Plugin) -->
<!-- output results in xml format -->
<plugins>::XMLReport</plugins>
<!-- follow named links from previous html page -->
<plugins>::Click</plugins>
<user_agent>Mozilla/5.0 (HTTP-WebTest)</user_agent>
<!-- send to these mail addresses (element may be repeated) -->
<mail_addresses>NOC <no...@is...d></mail_addresses>
<mail_from>WebTest <we...@is...d></mail_from>
<!-- do not specify the email element for now; this will break the XML report -->
<!-- basic auth. credentials, used if requested by http server -->
<auth>user</auth>
<auth>secretpass</auth>
</param>
<!-- test groups specify tests to apply to a html page
test_name: a distinctive name for the report
url: location of the page to test
method: get, post (default get)
-->
<testgroup test_name="Yahoo Home" url="http://www.yahoo.com/">
<comment>Test yahoo homepage</comment>
<text_require><![CDATA[</html>]]></text_require>
<text_require>Yahoo!</text_require>
<text_forbid>Internal Server Error</text_forbid>
</testgroup>
<testgroup test_name="Slashdot - Front page" url="http://slashdot.org/">
<comment>Front page of Slashdot site</comment>
<!-- no explicit tests (response will always be checked) -->
<!-- use result page for next testgroup: follow named link -->
</testgroup>
<testgroup test_name="Slashdot 1st article">
<comment>Topmost Slashdot story</comment>
<!-- parameter for Click plugin: request url targeted by this link -->
<!-- NOTE: this is interpreted as Perl regex, so be careful with special chars -->
<click_link><![CDATA[.*Read More\.\.\..*]]></click_link>
<!-- contrieved example: check if view modifier form is available -->
<text_require>Threshold:</text_require>
</testgroup>
<testgroup test_name="This should fail" url="http://www.yahoo.com/thisshouldnotexist">
<comment>Test non-existing document</comment>
<text_require><![CDATA[</html>]]></text_require>
<text_require>Yahoo!</text_require>
<text_require>Sorry, the page you requested was not found</text_require>
<text_forbid>Internal Server Error</text_forbid>
</testgroup>
</WebTest>
--- NEW FILE: webtest ---
#!/usr/bin/perl -w
use HTTP::WebTest;
use XML::Simple;
use Getopt::Long;
my %opt;
GetOptions(\%opt, qw(config=s help verbose dump debug name=s) );
&usage() if ((! -f $opt{config}) || $opt{help});
## read and parse configuration from xml file
my $cfg = XMLin($opt{config},
suppressempty => '',
forcecontent => 0,
forcearray => &ARRYPARAMS,
);
if ($opt{debug}) {
$cfg->{param}->{default_report} = 'yes';
$cfg->{param}->{plugins} = [];
$cfg->{param}->{show_headers} = 'yes';
$cfg->{param}->{show_html} = 'yes';
}
# delete locally invented <comment/> elements from tests
# in order to avoid possible name clashes
foreach my $t (@{$cfg->{testgroup}}) {
delete $t->{comment};
}
# same for mail_method parameter
delete $cfg->{param}->{mail_method};
if ($opt{name}) {
my @tests;
foreach my $t (@{$cfg->{testgroup}}) {
push @tests, $t if ($t->{test_name} =~ /\Q$opt{name}\E/i);
}
$cfg->{testgroup} = \@tests;
}
if ($opt{dump}) {
eval { use Data::Dumper; };
print Dumper($cfg);
exit;
}
my $wt = HTTP::WebTest->new;
$wt->run_tests( $cfg->{testgroup}, $cfg->{param});
### UTIL ###
sub usage {
print <<" EU";
webtest --config=<xmlfile> [options]
--config=file - read webtests from xml file "file"
--verbose - be verbose
--dump - dump parsed configuration, exit
--debug - output full http-headers and html content
in plain text representation
--name=string - run only test group(s) containing "string"
in the name, case-insensitive
--help - this
EU
exit;
}
## ARRAYPARAMS
## all xml elements which need to be expanded to array refs
## even if they contain only one element:
sub ARRYPARAMS { return [ qw(
testgroup
plugins
cookie
text_require text_forbid
regex_require regex_forbid
date_maxage date_start date_end
mail_addresses
) ];
}
--- NEW FILE: webtest.sh ---
#!/bin/sh
#
# script to demonstrate some possibilities of XMLReport plugin
#
# Prerequisites:
XSLT=xsltproc # part of Gnome/LibXML
WEBTEST="./webtest" # perl wrapper
SENDMAIL="/bin/true" # replace by Sendmail, e.g.
# SENDMAIL="/usr/sbin/sendmail -t"
$WEBTEST --config="testdefs.xml" >out1.xml
if [ ! -s out1.xml ]
then
echo "Empty test output 'out1.xml', further processing stopped."
exit 1
fi
# generate testscript for failed tests only
$XSLT --param testdoc "'../testdefs.xml'" transform/extract-failed.xsl out1.xml >failed1.xml
# wait before retrying failed tests
sleep 5
# 2nd iteration: run only tests that failed in 1st round
$WEBTEST --config="failed1.xml" >out2.xml
# merge results into enhanced test report
$XSLT --param merge "'../out2.xml'" --param testdoc "'../testdefs.xml'" \
transform/merge-results.xsl out1.xml >result.xml
# generate sidebar HTML
$XSLT transform/sidebar.xsl result.xml >"sidebar.html"
# generate main report HTML
$XSLT transform/content.xsl result.xml >"content.html"
# generate email; will be empty if all tests passed
$XSLT --param testdoc "'../testdefs.xml'" transform/email.xsl out2.xml >email.txt
if [ -s email.txt ]; then $SENDMAIL <email.txt ; fi
|