http://search.cpan.org.

" />
x
Loading
 Loading
Hello, Guest | Login | Register

The Health of Your Site, Part 2

In last month’s column, I showed how to create a web site testing tool based on Perl’s own testing framework and the WWW::Mechanize module. For reference, I’ve reproduced the code developed in last month’s article in Listing One. The test code verifies the proper operation of a web site, in this case, http://search.cpan.org.

In last month’s column, I showed how to create a web site testing tool based on Perl’s own testing framework and the WWW::Mechanize module. For reference, I’ve reproduced the code developed in last month’s article in Listing One. The test code verifies the proper operation of a web site, in this case, http://search.cpan.org.

Listing One: A testing program to diagnose site health

 01 #!/usr/bin/perl 02 use Test::More tests => 9; 03 use WWW::Mechanize; 04 isa_ok(my $a = WWW::Mechanize->new, “WWW::Mechanize”); 05  06 $a->timeout(1); 07 $a->get(”http://search.cpan.org/“); 08 is($a->status, 200, “fetched /”); 09 like($a->title, qr/The CPAN Search Site/, “/ title matches”); 10  11 SKIP: { 12 ok($a->follow_link( text => ‘FAQ’ ), “follow FAQ link”) 13 or skip “missing FAQ link”, 2; 14  15 SKIP: { 16 is($a->status, 200, “fetched FAQ page”) 17 or skip “bad FAQ fetch”, 1; 18 like($a->content, qr/Frequently Asked Questions/, “FAQ content matches”); 19 $a->back; 20 } 21 } 22  23 SKIP: { 24 ok($a->form_number(1), “select query form”) 25 or skip “cannot select query form”, 2; 26 $a->set_fields(query => “PETDANCE”, mode => ‘author’); 27 $a->click(); 28  29 SKIP: { 30 is($a->status, 200, “query returned good for ‘author’”) 31 or skip “missing author page”, 1; 32 like($a->content, qr/Andy Lester/, “found Andy Lester”); 33 $a->back; 34 } 35 } 

While invoking this program directly certainly gives an immediate…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. KDE 4.4: Does It Work Yet?
  2. Writing Custom Nagios Plugins with Python
  3. Power Up Linux GUI Apps
  4. Tweeting from the Command Line with Twyt
  5. When Memory Serves You: Using ramfs and tmpfs
Follow Linux Magazine
Rackspace