Re: [Http-webtest-general] using regex matches in later regexes
Brought to you by:
m_ilya,
richardanderson
From: Ilya M. <il...@ip...> - 2004-05-05 09:44:52
|
>>>>> "SW" == Schwarz, Wolfgang <sc...@am...> writes: SW> Hi, SW> I am new to Webtest and I couldn't find an answer to my question in the archives, yet. SW> I need to take a regex match from one test and make it part of the next regex required on the same page SW> and use it in a post on the following page. SW> Its an easy task in perl storeing the match in the $1 variable, done in various scripts, but webtest doesn't seem to like me doing it. SW> I tried it like this: SW> 'regex_require' => [ SW> 'order\.(\d+:\d+)', SW> 'order\.'.$1 SW> ] SW> although the first regex is successful the match is not stored and the variable is empty. Line "'order\.'.$1" is being evaluated by Perl at the time you define a data structure which defines a test. It is not being evaluated by Perl at the time when test is being run. In other words Line "'order\.'.$1" is being evaluated too early - before any match is being made. To make sure that code is being evaluted at the time when tests are being run you should replace a string which describes regular expression with a anonymous subroutine which returns a regexp. I.e. 'regex_require' => [ 'order\.(\d+:\d+)', sub { 'order\.'.$1 } ] This will cause content of the anonymous sub to be evaluted during test run. Unfortunately it still doesn't seem to work and I cannot quickly say why. Instead you can try following workaround: 'regex_require' => [ 'order\.(\d+:\d+)', sub { my $wt = shift; $wt->current_request->content =~ /order\.(\d+:\d+)/; 'order\.'.$1; } ] This workaround runs you regexp twice and uses result of second match to build a regexp to be used in the test. SW> REQUIRED REGEX SW> order\.(\d+:\d+) SUCCEED SW> order\. SUCCEED (BAD b/c I am expecting the regex to look like "order\.123:123456789" ) SW> what am I doing wrong here ? -- 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 |