Re: [Http-webtest-general] Re: last_test HTTP-WebTest-1.99_09
Brought to you by:
m_ilya,
richardanderson
From: Kevin B. <ke...@ri...> - 2002-11-05 17:19:46
|
Hi * Ilya Martynov <il...@ma...> [2002-11-04 20:50:58 +0300]: > > KB> [..snip..] > > KB> Unless you can see an easier way to accomplish this. > > Sure :) > > Untested code: > > [..snip..] works out great. it's looking much cleaner. thanks. > Anyway I've applied your patch and your code is in CVS > repository. Thanks you again for the patch. Looking into this a little further, I notice that my patch may not be so well thought out. In that patch I added the set last_test inside the loop (around line 130) in HTTP::WebTest::API and removed the line at 133 that was setting last_test to undef. I think now that the it is not necessary to add the $self->last_test($test); inside the testing loop since I notice that it is set in run_test at line 534. I noticed this since I was trying to access the $webtest->last_response inside a test to set the url based on the referral from the previous test. Roughly something like this run_tests([ { url => 'mysite.com', status_code => 302, handle_redirects => 'no', }, { url => sub { my $wt = shift; return $wt->last_response->headers->{'location'}; } }, However it seems that since last_test is set before the plugins are prepared at (at line 547) the plugin is not accessing the last_test, but rather the current one. (I'm guessing that $plugin->prepare_request is where the url parm gets processed. I haven't actually checked) My question is, is there any reason why you can't set last_test after you've processed the current test? I can see that you are using last_test in the subs that set all the last_request/last_response etc, so you could move the setting of these to the end of the run_test routine, after setting last_test. I've got a workaround by using the on_response hooks. I capture the location in the last test and set a var that I use in the next test. my $referral; run_tests([ { url => 'mysite.com', status_code => 302, handle_redirects => 'no', on_response => sub { my $wt = shift; $referral = $wt->last_response->headers->{'location'}; []; } }, { url => sub { $referral }, }, The method names are a little confusing though (for me). If I'm looking at the response in on_response I'd expect the method to be called 'response'. 'last_response' makes me think that it is referring to the last test's response. ;-) Food for thought thanks Kev |