Test:
Check http response code received from network for a webpage and continue furthur test case only if response code is 200
Learning:
Use LWP::Simple
getstore($url, $file) returns data received from network followed by response code. Data is saved to file.
For sucess cases, http response code should be 200.
getstore($url, $file) returns data received from network followed by response code. Data is saved to file.
For sucess cases, http response code should be 200.
Solution:
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";

No comments:
Post a Comment