Thursday, 2 October 2014

Test 9: Check that all links of webpage can be accessed successfully

Test:
Check that all links of webpage can be accessed successfully

Learning: 
get( $link->url ) will take care of relative URL also


Solution:

#!/usr/bin/perl
use Test::More;
use LWP::Simple;
use WWW::Mechanize;

#define number of planned test cases
plan tests => 700; 

my $m = WWW::Mechanize->new();
$m->get( "http://www.google.com/" );

ok( $m->success, 'Fetched OK' );

for my $link ( $m->links )
{
$m->get( $link->url );
print $link->text."\n".$link->url."\n";
ok( $m->success);
$m->back();
ok( $m->success, "Back successful");
print "\n";
}


output snapshot:

No comments:

Post a Comment