1

I want to test a .htaccess protected page with Test::WWW::Mechanize but I don't know how can I send credentials for the page? I couldn't find a function that can handle this.

ferhatelmas
  • 3,818
  • 1
  • 21
  • 25

1 Answers1

6
use Test::WWW::Mechanize;
my $mech = Test::WWW::Mechanize->new();
my ($user, $pass) = qw/user pass/;
$mech->credentials($user, $pass);
$mech->get_ok('http://example.com');
cjm
  • 61,471
  • 9
  • 126
  • 175
singingfish
  • 3,136
  • 22
  • 25
  • Is it counted as a test? When we get an agent from Test::WWW::Mechanize, there is no credentials procedure. – ferhatelmas Jul 28 '11 at 10:51
  • There definitely is. The method is inherited from the superclass WWW::Mechanize. Read a book about Object Orientation if you do not know the difference between method and procedure. - `credentials` is not a TAP emitting method like the various ones named `*_ok` found in Test::WWW::Mechanize. – daxim Jul 28 '11 at 13:23
  • @daxim I am totally new to perl so some things are blur but I had already done what I wanted. Anyway, thanks for your answer and [method vs procedure point](http://stackoverflow.com/questions/3036330/method-vs-function-vs-procedure-vs-class) – ferhatelmas Jul 28 '11 at 19:07