Tuesday, 30 September 2014

Test 3: Check the http response code from network

Test:
Check http response code received from network for a webpage and display result



Solution:

#!/usr/bin/perl

use Test::More;
use LWP::Simple;

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

#URL under test
my $url1 = "http://www.google.com";
my $url2 = "http://www.iamperl.com";

#getting content of webpage with http response code
my $content1 = getprint($url1); 
my $content2 = getprint($url2); 

#get response code
(my $response1)= $content1 =~ /(\d*)/;
(my $response2)= $content2 =~ /(\d*)/;

ok($response1 eq "200", "Http response code showed $response1");
ok($response2 eq "200", "Http response code showed $response2");


output snapshot:


No comments:

Post a Comment