1Mechanize(3)          User Contributed Perl Documentation         Mechanize(3)
2
3
4

NAME

6       Test::WWW::Mechanize - Testing-specific WWW::Mechanize subclass
7

VERSION

9       Version 1.14
10

SYNOPSIS

12       Test::WWW::Mechanize is a subclass of WWW::Mechanize that incorporates
13       features for web application testing.  For example:
14
15           use Test::More tests => 5;
16           use Test::WWW::Mechanize;
17
18           my $mech = Test::WWW::Mechanize->new;
19           $mech->get_ok( $page );
20           $mech->base_is( 'http://petdance.com/', 'Proper <BASE HREF>' );
21           $mech->title_is( "Invoice Status", "Make sure we're on the invoice page" );
22           $mech->content_contains( "Andy Lester", "My name somewhere" );
23           $mech->content_like( qr/(cpan⎪perl)\.org/, "Link to perl.org or CPAN" );
24
25       This is equivalent to:
26
27           use Test::More tests => 5;
28           use WWW::Mechanize;
29
30           my $mech = WWW::Mechanize->new;
31           $mech->get( $page );
32           ok( $mech->success );
33           is( $mech->base, 'http://petdance.com', 'Proper <BASE HREF>' );
34           is( $mech->title, "Invoice Status", "Make sure we're on the invoice page" );
35           ok( index( $mech->content, "Andy Lester" ) >= 0, "My name somewhere" );
36           like( $mech->content, qr/(cpan⎪perl)\.org/, "Link to perl.org or CPAN" );
37
38       but has nicer diagnostics if they fail.
39

CONSTRUCTOR

41       new
42
43       Behaves like, and calls, WWW::Mechanize's "new" method.  Any parms
44       passed in get passed to WWW::Mechanize's constructor.
45

METHODS

47       $mech->get_ok($url, [ \%LWP_options ,] $desc)
48
49       A wrapper around WWW::Mechanize's get(), with similar options, except
50       the second argument needs to be a hash reference, not a hash. Like
51       well-behaved "*_ok()" functions, it returns true if the test passed, or
52       false if not.
53
54       $mech->title_is( $str [, $desc ] )
55
56       Tells if the title of the page is the given string.
57
58           $mech->title_is( "Invoice Summary" );
59
60       $mech->title_like( $regex [, $desc ] )
61
62       Tells if the title of the page matches the given regex.
63
64           $mech->title_like( qr/Invoices for (.+)/
65
66       $mech->title_unlike( $regex [, $desc ] )
67
68       Tells if the title of the page matches the given regex.
69
70           $mech->title_unlike( qr/Invoices for (.+)/
71
72       $mech->base_is( $str [, $desc ] )
73
74       Tells if the base of the page is the given string.
75
76           $mech->base_is( "http://example.com/" );
77
78       $mech->base_like( $regex [, $desc ] )
79
80       Tells if the base of the page matches the given regex.
81
82           $mech->base_like( qr{http://example.com/index.php?PHPSESSID=(.+)});
83
84       $mech->base_unlike( $regex [, $desc ] )
85
86       Tells if the base of the page matches the given regex.
87
88           $mech->base_unlike( qr{http://example.com/index.php?PHPSESSID=(.+)});
89
90       $mech->content_is( $str [, $desc ] )
91
92       Tells if the content of the page matches the given string
93
94       $mech->content_contains( $str [, $desc ] )
95
96       Tells if the content of the page contains $str.
97
98       $mech->content_lacks( $str [, $desc ] )
99
100       Tells if the content of the page lacks $str.
101
102       $mech->content_like( $regex [, $desc ] )
103
104       Tells if the content of the page matches $regex.
105
106       $mech->content_unlike( $regex [, $desc ] )
107
108       Tells if the content of the page does NOT match $regex.
109
110       $mech->has_tag( $tag, $text [, $desc ] )
111
112       Tells if the page has a $tag tag with the given content in its text.
113
114       $mech->has_tag_like( $tag, $regex [, $desc ] )
115
116       Tells if the page has a $tag tag with the given content in its text.
117
118       $mech->followable_links()
119
120       Returns a list of links that Mech can follow.  This is only http and
121       https links.
122
123       $mech->page_links_ok( [ $desc ] )
124
125       Follow all links on the current page and test for HTTP status 200
126
127           $mech->page_links_ok('Check all links');
128
129       $mech->page_links_content_like( $regex,[ $desc ] )
130
131       Follow all links on the current page and test their contents for
132       $regex.
133
134           $mech->page_links_content_like( qr/foo/,
135             'Check all links contain "foo"' );
136
137       $mech->page_links_content_unlike( $regex,[ $desc ] )
138
139       Follow all links on the current page and test their contents do not
140       contain the specified regex.
141
142           $mech->page_links_content_unlike(qr/Restricted/,
143             'Check all links do not contain Restricted');
144
145       $mech->links_ok( $links [, $desc ] )
146
147       Follow specified links on the current page and test for HTTP status
148       200.  The links may be specified as a reference to an array containing
149       WWW::Mechanize::Link objects, an array of URLs, or a scalar URL name.
150
151           my @links = $mech->find_all_links( url_regex => qr/cnn\.com$/ );
152           $mech->links_ok( \@links, 'Check all links for cnn.com' );
153
154           my @links = qw( index.html search.html about.html );
155           $mech->links_ok( \@links, 'Check main links' );
156
157           $mech->links_ok( 'index.html', 'Check link to index' );
158
159       $mech->link_status_is( $links, $status [, $desc ] )
160
161       Follow specified links on the current page and test for HTTP status
162       passed.  The links may be specified as a reference to an array contain‐
163       ing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL
164       name.
165
166           my @links = $mech->followable_links();
167           $mech->link_status_is( \@links, 403,
168             'Check all links are restricted' );
169
170       $mech->link_status_isnt( $links, $status [, $desc ] )
171
172       Follow specified links on the current page and test for HTTP status
173       passed.  The links may be specified as a reference to an array contain‐
174       ing WWW::Mechanize::Link objects, an array of URLs, or a scalar URL
175       name.
176
177           my @links = $mech->followable_links();
178           $mech->link_status_isnt( \@links, 404,
179             'Check all links are not 404' );
180
181       $mech->link_content_like( $links, $regex [, $desc ] )
182
183       Follow specified links on the current page and test the resulting con‐
184       tent of each against $regex.  The links may be specified as a reference
185       to an array containing WWW::Mechanize::Link objects, an array of URLs,
186       or a scalar URL name.
187
188           my @links = $mech->followable_links();
189           $mech->link_content_like( \@links, qr/Restricted/,
190               'Check all links are restricted' );
191
192       $mech->link_content_unlike( $links, $regex [, $desc ] )
193
194       Follow specified links on the current page and test that the resulting
195       content of each does not match $regex.  The links may be specified as a
196       reference to an array containing WWW::Mechanize::Link objects, an array
197       of URLs, or a scalar URL name.
198
199           my @links = $mech->followable_links();
200           $mech->link_content_unlike( \@links, qr/Restricted/,
201             'No restricted links' );
202
203       $mech->follow_link_ok( \%parms [, $comment] )
204
205       Makes a "follow_link()" call and executes tests on the results.  The
206       link must be found, and then followed successfully.  Otherwise, this
207       test fails.
208
209       %parms is a hashref containing the parms to pass to "follow_link()".
210       Note that the parms to "follow_link()" are a hash whereas the parms to
211       this function are a hashref.  You have to call this function like:
212
213           $mech->follow_link_ok( {n=>3}, "looking for 3rd link" );
214
215       As with other test functions, $comment is optional.  If it is supplied
216       then it will display when running the test harness in verbose mode.
217
218       Returns true value if the specified link was found and followed suc‐
219       cessfully.  The HTTP::Response object returned by follow_link() is not
220       available.
221
222       $mech->stuff_inputs( [\%options] )
223
224       Finds all free-text input fields (text, textarea, and password) in the
225       current form and fills them to their maximum length in hopes of finding
226       application code that can't handle it.  Fields with no maximum length
227       and all textarea fields are set to 66000 bytes, which will often be
228       enough to overflow the data's eventual recepticle.
229
230       There is no return value.
231
232       If there is no current form then nothing is done.
233
234       The hashref $options can contain the following keys:
235
236       * ignore
237           hash value is arrayref of field names to not touch, e.g.:
238
239               $mech->stuff_inputs( {
240                   ignore => [qw( specialfield1 specialfield2 )],
241               } );
242
243       * fill
244           hash value is default string to use when stuffing fields.  Copies
245           of the string are repeated up to the max length of each field.
246           E.g.:
247
248               $mech->stuff_inputs( {
249                   fill => '@'  # stuff all fields with something easy to recognize
250               } );
251
252       * specs
253           hash value is arrayref of hashrefs with which you can pass detailed
254           instructions about how to stuff a given field.  E.g.:
255
256               $mech->stuff_inputs( {
257                   specs=>{
258                       # Some fields are datatype-constrained.  It's most common to
259                       # want the field stuffed with valid data.
260                       widget_quantity => { fill=>'9' },
261                       notes => { maxlength=>2000 },
262                   }
263               } );
264
265           The specs allowed are fill (use this fill for the field rather than
266           the default) and maxlength (use this as the field's maxlength
267           instead of any maxlength specified in the HTML).
268

TODO

270       Add HTML::Lint and HTML::Tidy capabilities.
271

AUTHOR

273       Andy Lester, "<andy at petdance.com>"
274

BUGS

276       Please report any bugs or feature requests to "bug-test-www-mechanize
277       at rt.cpan.org", or through the web interface at
278       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-WWW-Mechanize>.  I
279       will be notified, and then you'll automatically be notified of progress
280       on your bug as I make changes.
281

SUPPORT

283       You can find documentation for this module with the perldoc command.
284
285           perldoc Test::WWW::Mechanize
286
287       You can also look for information at:
288
289       * AnnoCPAN: Annotated CPAN documentation
290           <http://annocpan.org/dist/Test-WWW-Mechanize>
291
292       * CPAN Ratings
293           <http://cpanratings.perl.org/d/Test-WWW-Mechanize>
294
295       * RT: CPAN's request tracker
296           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-WWW-Mechanize>
297
298       * Search CPAN
299           <http://search.cpan.org/dist/Test-WWW-Mechanize>
300

ACKNOWLEDGEMENTS

302       Thanks to Michael Schwern, Mark Blackman, Mike O'Regan, Shawn
303       Sorichetti, Chris Dolan, Matt Trout, MATSUNO Tokuhiro, and Pete
304       Krawczyk for patches.
305
307       Copyright 2004-2007 Andy Lester, all rights reserved.
308
309       This program is free software; you can redistribute it and/or modify it
310       under the same terms as Perl itself.
311
312
313
314perl v5.8.8                       2007-05-11                      Mechanize(3)
Impressum