<?xml version="1.0" encoding="windows-1252"?>
<node id="447314" title="WWW::Mechanize follow meta refreshes" created="2005-04-13 05:40:06" updated="2005-08-07 20:31:17">
<type id="1980">
snippet</type>
<author id="64906">
simon.proctor</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
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.  
&lt;br&gt;&lt;br&gt;
&lt;b&gt;Update&lt;/b&gt;: 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 :).</field>
<field name="snippetcode">
&lt;CODE&gt;
sub meta_refresh
{
	my $mech = shift;
	my $expected_url = shift;
	
	my $url;
	
	if($mech-&gt;content() =~ /&lt;meta http-equiv="refresh" content="0;url=([^"]*)"/)
	{
		$url = $1;
	}

	cmp_ok($expected_url, 'eq', $url, "The meta refresh returns the expected URL");
	
	$mech-&gt;get( $expected_url );
	ok($mech-&gt;success(), "URL loaded successfully");
}
&lt;/CODE&gt;
So call it like this:
&lt;code&gt;
   # Code to cause the refresh to appear not shown.
   
   # Check the refresh and follow
   meta_refresh($mech, '/index.cgi?rm=home');
&lt;/code&gt;</field>
</data>
</node>
