NAME
WWW::Mechanize::TreeBuilder
SYNOPSIS
use Test::More tests => 2;
use Test::WWW::Mechanize;
# or
# use WWW::Mechanize;
# or
# use Test::WWW::Mechanize::Catalyst 'MyApp';
my $mech = WWW::Mechanize->new;
# or
#my $mech = Test::WWW::Mechanize::Catalyst->new;
# etc. etc.
WWW::Mechanize::TreeBuilder->meta->apply($mech);
$mech->get_ok('/');
ok( $mech->look_down(_tag => 'p')->as_trimmed_text, 'Some text', 'It worked' );
DESCRIPTION
This module combines WWW::Mechanize and HTML::TreeBuilder. Why? Because I've seen too much code like the following:
like($mech->content, qr{<p>some text</p>}, "Found the right tag");
Which is just all flavours of wrong - its akin to processing XML with regexps. Instead, do it like the following:
ok($mech->look_down(_tag => 'p', sub { $_[0]->as_trimmed_text eq 'some text' })
The anon-sub there is a bit icky, but this means that if the p tag should happen to add attributes to the <p>
tag (such as an id or a class) it will still work and find the right tag.
All of the methods avaiable on HTML::Element (that aren't 'private' - i.e. everything that doesn't begin with an underscore) such as look_down
or find
are automatically delegated to $mech->tree
through the magic of Moose.
METHODS
Everything in WWW::Mechanize (or which ever sub class you apply it to) and all public methods from HTML::Element.
AUTHOR
Ash Berlin <ash@cpan.org>
LICENSE
Same as Perl 5.8, or at your option any later version of Perl.