Use the power of XPath expressions to validate the structure of your XML and HTML documents.
Synopsis
use Test::More tests = > 5;
use Test::XPath;
my $xml = < < 'XML';
< html >
< head >
< title >Hello< /title >
< style type="text/css" src="foo.css" >< /style >
< style type="text/css" src="bar.css" >< /style >
< /head >
< body >
< h1 >Welcome to my lair.< /h1 >
< /body >
< /html >
XML
my $tx = Test::XPath- >new( xml = > $xml );
$tx- >ok( '/html/head', 'There should be a head' );
$tx- >is( '/html/head/title', 'Hello', 'The title should be correct' );
# Recursing into a document:
my @css = qw(foo.css bar.css);
$tx- >ok( '/html/head/style[@type="text/css"]', sub {
my $css = shift @css;
shift- >is( './@src', $css, "Style src should be $css");
}, 'Should have style' );
# Better yet, use PerlX::MethodCallWithBlock:
use PerlX::MethodCallWithBlock;
my @css = qw(foo.css bar.css);
use PerlX::MethodCallWithBlock;
$tx- >ok( '/html/head/style[@type="text/css"]', 'Should have style' ) {
my $css = shift @css;
shift- >is( './@src', $css, "Style src should be $css");
};
Product's homepage
Requirements:
· Perl