[Http-webtest-general] Re: last_test HTTP-WebTest-1.99_09
Brought to you by:
m_ilya,
richardanderson
From: Ilya M. <il...@ma...> - 2002-11-04 17:53:42
|
>>>>> On Mon, 4 Nov 2002 17:43:15 +0100, Kevin Baker <ke...@ri...> said: KB> Hi KB> sorry for the late reply, been on leave... KB> I'm trying to get access to the value on the cookie returned since I need KB> know the cookie value to set as a param in a subsequent call KB> So I run one web test to get the cookie and then extract it KB> from the last_response and then run some more tests. KB> [..snip..] KB> Unless you can see an easier way to accomplish this. Sure :) Untested code: my $wt = HTTP::WebTest->new; # run tests to get cookie $wt->run_tests([ ... { ... param => { sid => sub { my $wt = shift; my($cookie) = get_cookies($wt->last_response); return $cookie->[2]; } }, ... } ... ]); sub get_cookies { my $response = shift; # parse cookies in response use HTTP::Cookies; my $cookie_jar = HTTP::Cookies->new; $cookie_jar->extract_cookies($response); # suck cookies out of cookie jar via scan my @cookies; $cookie_jar->scan(sub {push @cookies, [@_]}); @cookies } This code can probably be made even simplier as you can access cookie jar used by HTTP-WebTest and which should contain all collected cookies directly via $webtest->user_agent->cookie_jar. Anyway I've applied your patch and your code is in CVS repository. Thanks you again for the patch. -- Ilya Martynov, il...@ip... CTO IPonWEB (UK) Ltd Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net Personal website - http://martynov.org |