My web app (for IIS reasons) uses meta refreshes to redirect the user around. I test these redirects with the code below. I've used a regex as my refresh template is fixed and very, very simple. However, if yours isn't/aren't then you should replace the regex with a call to something like HTML::TokeParser.
Update: fixed silly mistake as hilighted below. Also fixed what was, for my test suite, a logic error. The final get call must be to $expected_url and not $url. If your test quite works differently then use $url instead :).
Update: fixed silly mistake as hilighted below. Also fixed what was, for my test suite, a logic error. The final get call must be to $expected_url and not $url. If your test quite works differently then use $url instead :).
So call it like this:sub meta_refresh { my $mech = shift; my $expected_url = shift; my $url; if($mech->content() =~ /<meta http-equiv="refresh" content="0;url= +([^"]*)"/) { $url = $1; } cmp_ok($expected_url, 'eq', $url, "The meta refresh returns the ex +pected URL"); $mech->get( $expected_url ); ok($mech->success(), "URL loaded successfully"); }
# Code to cause the refresh to appear not shown. # Check the refresh and follow meta_refresh($mech, '/index.cgi?rm=home');
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: WWW::Mechanize follow meta refreshes
by merlyn (Sage) on Apr 13, 2005 at 14:38 UTC | |
by simon.proctor (Vicar) on Apr 13, 2005 at 15:42 UTC | |
Re: WWW::Mechanize follow meta refreshes
by Kanji (Parson) on Apr 14, 2005 at 15:19 UTC | |
by simon.proctor (Vicar) on Apr 15, 2005 at 09:00 UTC | |
Re: WWW::Mechanize follow meta refreshes
by jbrugger (Parson) on Apr 14, 2005 at 06:10 UTC | |
Re: WWW::Mechanize follow meta refreshes
by mhi (Friar) on Aug 28, 2005 at 20:46 UTC |
Back to
Cool Uses for Perl