Wednesday, 8 October 2014

Test 15 :Set up new user agent and verify the request is sent via that user agent

Test:
Set up new user agent and verify the request is sent via that user agent

Learning: 
$mech->agent_alias( 'Windows IE 6' ); is used to set user agent.

possible UA can be:
  • Windows IE 6
  • Windows Mozilla
  • Mac Safari
  • Mac Mozilla
  • Linux Mozilla
  • Linux Konqueror


Solution:

use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
$mech->agent_alias( 'Windows IE 6' );
$mech->get('http://whatsmyuseragent.com/');
my $data = $mech->content;

(my $ua)= $data =~ /<h2 class="info">(.*)<\/h2>/;

print $ua;


output snapshot:

No comments:

Post a Comment