AW: [Http-webtest-general] using regex matches in later regexes
Brought to you by:
m_ilya,
richardanderson
From: Schwarz, W. <sc...@am...> - 2004-05-05 13:18:44
|
sorry for bothering again, hopefully the last time.=20 I found out that=20 $wt->current_request->content=20 doesn't return any data, thats the reason I get no match. do I need to add some module to have that work ? I currently use : use strict; use lib '/usr/lib/perl5/site_perl/5.6.0'; use HTTP::WebTest; I am calling webtest from a perl-script with: my $wt =3D new HTTP::WebTest; $wt->run_tests( $test1, $params); and this is the part of my testsuite that breaks. # test 6=20 { 'test_name' =3D> 'step6', 'url' =3D> '........', 'method' =3D> 'post', 'form_name' =3D> '<form name=3D"">', 'params' =3D> { 'submit.x' =3D> '0', 'submit.y' =3D> '0' }, 'regex_require' =3D> [ 'order\.\d+:\d+', sub { my $wt =3D shift; $wt->current_request->content =3D~ = /(order\.\d+)/) 'order\.'.$1; }, ], 'regex_forbid' =3D> [ 'failed', ] }, thanks for your help Wolle -----Urspr=FCngliche Nachricht----- Von: Ilya Martynov [mailto:il...@ip...]=20 Gesendet: Mittwoch, 5. Mai 2004 11:45 An: Schwarz, Wolfgang Cc: htt...@li... Betreff: Re: [Http-webtest-general] using regex matches in later regexes >>>>> "SW" =3D=3D Schwarz, Wolfgang <sc...@am...> writes: SW> Hi,=20 SW> I am new to Webtest and I couldn't find an answer to my=20 question in the archives, yet. SW> I need to take a regex match from one test and make it part=20 of the next regex required on the same page=20 SW> and use it in a post on the following page.=20 SW> Its an easy task in perl storeing the match in the $1=20 variable, done in various scripts, but webtest doesn't seem to=20 like me doing it. SW> I tried it like this: SW> 'regex_require' =3D> [ SW> 'order\.(\d+:\d+)',=09 SW> 'order\.'.$1 SW> ] SW> although the first regex is successful the match is not=20 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' =3D> [ 'order\.(\d+:\d+)',=09 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' =3D> [ 'order\.(\d+:\d+)',=09 sub { my $wt =3D shift; $wt->current_request->content =3D~=20 /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=20 am expecting the regex to look like "order\.123:123456789" ) SW> what am I doing wrong here ? --=20 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 |