NAME
Test::WWW::Mechanize - The great new Test::WWW::Mechanize!
Version
Version 0.06
Synopsis
Test::WWW::Mechanize is a subclass of WWW::Mechanize that incorporates features that make sense for doing web application testing. For example:
$mech->get( $page );
$mech->title_is( "Invoice Status",
"Make sure we're on the invoice page" );
This is equivalent to:
$mech->get( $page );
is( $mech->title, "Invoice Status",
"Make sure we're on the invoice page" );
but has nicer error handling.
Constructor
new
Behaves like, and calls, WWW::Mechanize's new
method. Any parms passed in get passed to WWW::Mechanize's constructor.
Methods
title_is( $str [, $msg ] )
Tells if the title of the page is the given string.
$mech->title_is( "Invoice Summary" );
title_like( $regex [, $msg ] )
Tells if the title of the page matches the given regex.
$mech->title_like( qr/Invoices for (.+)/
content_is( $str [, $msg ] )
Tells if the content of the page matches the given string
content_like( $regex [, $msg ] )
Tells if the content of the page matches the given regex
page_links_ok( [ $msg ] )
Follow all links on the current page and test for HTTP status 200
$mech->page_links_ok('Check all links');
page_links_content_like( $regex,[ $msg ] )
Follow all links on the current page and test their contents for the specified regex.
$mech->page_links_content_like(qr/html/,
'Check all links contain html');
page_links_content_unlike( $regex,[ $msg ] )
Follow all links on the current page and test their contents do not contain the specified regex.
$mech->page_links_content_unlike(qr/Restricted/,
'Check all links do not contain Restricted');
links_ok( $links [, $msg ] )
Check the current page for specified links and test for HTTP status 200. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
my @links = $mech->find_all_links( url_regex => qr/cnn\.com$/ );
$mech->links_ok( \@links, 'Check all links for cnn.com' );
my @links = qw( index.html search.html about.html );
$mech->links_ok( \@links, 'Check main links' );
$mech->links_ok( 'index.html', 'Check link to index' );
link_status_is( $links, $status [, $msg ] )
Check the current page for specified links and test for HTTP status passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
my @links = $mech->links();
$mech->link_status_is( \@links, 403,
'Check all links are restricted' );
link_status_isnt( $links, $status [, $msg ] )
Check the current page for specified links and test for HTTP status passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
my @links = $mech->links();
$mech->link_status_isnt( \@links, 404,
'Check all links are not 404' );
link_content_like( $links, $regex [, $msg ] )
Check the current page for specified links and test the content of each for the regex passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
my @links = $mech->links();
$mech->link_content_like( \@links, qr/Restricted/,
'Check all links are restricted' );
link_content_unlike( $links, $regex [, $msg ] )
Check the current page for specified links and test the content of each does not contain regex passed. The links may be specified as a reference to an array containing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
my @links = $mech->links();
$mech->link_content_like( \@links, qr/Restricted/,
'Check all links are restricted' );
To-do
Test suite
Add HTML::Lint and HTML::Tidy capabilities.
BUGS
Please report any bugs or feature requests to bug-test-www-mechanize@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COPYRIGHT & LICENSE
Copyright 2004 Andy Lester, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Andy Lester, <andy@petdance.com>
ACKNOWLEDGEMENTS
Thanks to Shawn Sorichetti for big help and chunks of code.