i use www::mechanize::shell test stuff.
my code this:
#!/usr/bin/perl use www::mechanize; use http::cookies; $url = "http://mysite/app/login.jsp"; $username = "username"; $password = "asdfasdf"; $mech = www::mechanize->new(); $mech->cookie_jar(http::cookies->new()); $mech->get($url); $mech->form_number(1); $mech->field(j_username => $username); $mech->field(j_password => $password); $mech->click(); $mech->follow_link(text => "link a", n => 1); $mech->follow_link(text => "link b", n => 1);
........................ ........................ ........................ etc, etc.
the problem next:
link b (web_page_b.html), make redirect web_page_x.html
if print contents of $mech->content(), display web_page_b.html
but need display web_page_x.html,to automatically submit html form (web_page_x.html)
the question is:
how can web_page_x.html ?
thanks
why don't first test see if code containing redirect (i'm guessing it's <meta>
tag?) exists on web_page_b.html
, go directly next page once you're sure that's browser have done.
this like:
$mech->follow_link(text => "link b", n => 1); unless($mech->content() =~ /<meta http-equiv="refresh" content="5;url=(.*?)">/i) { die("test failed: web_page_b.html not contain meta refresh tag!"); } $expected_redirect = $1; # should 'web_page_x.html' $mech->get($expected_redirect); # might need add server name url
incidentally, if you're doing kind of testing www::mechanize
, should check out test::www::mechanize , other perl testing modules! make life lot easier.
Comments
Post a Comment