Monday, 29 September 2014

Test 1: Check the title of webpage

Test:
Check the title of webpage and display result

Learning: 
Use LWP::Simple
It allows you to get content of any webpage by a simple code- get($url)


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 source code of webpage
my $content = get($url); 

#Search string between <title> and</title>
(my $str)= $content =~ /<title>(.*)<\/title>/;

ok($str eq "Google", "Title of $url showed $str");


output snapshot:

No comments:

Post a Comment