Tuesday, 30 September 2014

Test 4: Continue to test if response code is 200, otherwise exit test

Test:
Check http response code received from network for a webpage and continue furthur test case only if response code is 200


Solution:

#!/usr/bin/perl

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

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

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

#getting content of webpage with http response code and store in file abc
my $content = getstore($url,abc); 

#get response code
(my $response)= $content =~ /(\d*)/;

if($response ne "200")
{
ok($response eq "200", "Http response code is not 200 showed 

$response");
exit;
}
ok($response eq "200", "Http response code is 200..we can continue of test");

#if below line is printed means 200 was received as response code and we are 

running next test case now
print "test case 2\n";


output snapshot:


No comments:

Post a Comment