Fetching contributors…
Cannot retrieve contributors at this time
55 lines (39 sloc) 2.05 KB


Test::WWW::Mechanize is a subclass of the Perl module WWW::Mechanize that incorporates features for web application testing. For example:

use Test::WWW::Mechanize;

my $mech = Test::WWW::Mechanize->new;
$mech->get_ok( $page );
$mech->base_is( '', 'Proper <BASE HREF>' );
$mech->title_is( 'Invoice Status', "Make sure we're on the invoice page" );
$mech->text_contains( 'Andy Lester', 'My name somewhere' );
$mech->content_like( qr/(cpan|perl)\.org/, 'Link to or CPAN' );
$mech->header_is( 'Cache-Control', 'private', 'Caching is turned off' );
$mech->lacks_header_ok( 'X-Foo', 'Does not have the X-Foo header' );

This is equivalent to:

use WWW::Mechanize;

my $mech = WWW::Mechanize->new;
$mech->get( $page );
ok( $mech->success );
is( $mech->base, '', 'Proper <BASE HREF>' );
is( $mech->title, 'Invoice Status', "Make sure we're on the invoice page" );
ok( index( $mech->content( format => 'text' ), 'Andy Lester' ) >= 0, 'My name somewhere' );
like( $mech->content, qr/(cpan|perl)\.org/, 'Link to or CPAN' );
is( $mech->response->header( 'Cache-Control' ), 'private', 'Caching is turned off' );
ok( !defined $mech->response->header( 'X-Foo' ), 'Does not have the X-Foo header' );

but has nicer diagnostics if they fail.


To install this module, run the following commands:

perl Makefile.PL
make test
make install


Copyright (C) 2004-2016 Andy Lester

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.