You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Grace Li <Gr...@thespigroup.com> on 2004/09/24 20:41:08 UTC

A problem while trying foreach+regex example

Hi all,

I am trying the example testplan linked in the section 'foreach
controller' in jmeter manual.  It is am example using the combination of
foreach and regex.

I gave a link to a real html page which has several links inside. But
the test result shows http request failure. Looking into the response
data, it could be found that ${returnVar} was not set a value. It's
either the regular expression is not right or something else wrong.

Can anyone shed me a light?

thanks!
Grace


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: A problem while trying foreach+regex example

Posted by sebb <se...@gmail.com>.
Just found another problem with the demo - the Regex Extractor is a
Post-Processor, so gets applied to all Samples in its scope. This
includes the samples generated by the For Each Controller.

I've updated the demo to make the Regex Extractor a child of the
initial Sampler - and renamed the Samplers to make the Tree Output
clearer.

By the way, if you want to process links for the host
http://www.xxx.yyy/ only, you could use the RE:

<a href="(?:http://www.xxx.yyy)?([^"]+)"

This will skip prefixes of the form http://www.xxx.yyy

BTW, I should have included the ?:  in the generic RE.
The ?: stops the () from capturing any data, so $1$ is still the
contents of the second parentheses. Otherwise the template would need
to be changed to $2$.

HTH


On Sat, 25 Sep 2004 00:13:06 +0100, sebb <se...@gmail.com> wrote:
> Actually, it was easier than I thought, using the regex coach:
> 
> <a href="(http.?://[^/]+)?([^"]+)"
> 
> However, this still only works for URLs on the same host, so I've not
> updated the example further.
> 
> [If the HTTP Samplers could accept a full URL in one field, this would
> work, but this might make other tests more difficult.]
> 
> 
> 
> On Fri, 24 Sep 2004 23:52:15 +0100, sebb <se...@gmail.com> wrote:
> > You're right - the regex is wrong - it should be:
> >
> > <a href="([^"]+)"
> >
> > rather than
> >
> > <a href="([^"])"
> >
> > which will only match
> >
> > <a href="?"
> >
> > where ? is any single character.
> >
> > Adding the + means it will match 1 or more characters (any character
> > except " - so that it stops when it reaches the closing "..
> >
> > Fixing this allows the regex to work, however as it stands it will
> > only work with URLs that don't contain the host name, because the
> > result is used in the path field.
> >
> > For example: <a href="/index.html"> should work, but <a
> > href="http://www.host.tld/fred.html"> won't.
> >
> > I'll fix the sample shortly to add the +; fixing it so that it works
> > with all kinds of URLs is probably much harder.
> >
> > The reason that the returnVar is not set is because the regex
> > extractor behaves differently for a negative match number, and does
> > not set inputVar_1 to the default if no matches were found.
> >
> > Thanks for reporting the problem - sorry for any inconvenience you were caused.
> >
> > S.
> > P.S. The regex coach is well worth investigating - see link from
> > JMeter Wiki http://wiki.apache.org/jakarta-jmeter/RegularExpressions
> >
> >
> >
> > On Fri, 24 Sep 2004 14:41:08 -0400, Grace Li <gr...@thespigroup.com> wrote:
> > > Hi all,
> > >
> > > I am trying the example testplan linked in the section 'foreach
> > > controller' in jmeter manual.  It is am example using the combination of
> > > foreach and regex.
> > >
> > > I gave a link to a real html page which has several links inside. But
> > > the test result shows http request failure. Looking into the response
> > > data, it could be found that ${returnVar} was not set a value. It's
> > > either the regular expression is not right or something else wrong.
> > >
> > > Can anyone shed me a light?
> > >
> > > thanks!
> > > Grace
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >
> > >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: A problem while trying foreach+regex example

Posted by sebb <se...@gmail.com>.
Actually, it was easier than I thought, using the regex coach:

<a href="(http.?://[^/]+)?([^"]+)"

However, this still only works for URLs on the same host, so I've not
updated the example further.

[If the HTTP Samplers could accept a full URL in one field, this would
work, but this might make other tests more difficult.]

On Fri, 24 Sep 2004 23:52:15 +0100, sebb <se...@gmail.com> wrote:
> You're right - the regex is wrong - it should be:
> 
> <a href="([^"]+)"
> 
> rather than
> 
> <a href="([^"])"
> 
> which will only match
> 
> <a href="?"
> 
> where ? is any single character.
> 
> Adding the + means it will match 1 or more characters (any character
> except " - so that it stops when it reaches the closing "..
> 
> Fixing this allows the regex to work, however as it stands it will
> only work with URLs that don't contain the host name, because the
> result is used in the path field.
> 
> For example: <a href="/index.html"> should work, but <a
> href="http://www.host.tld/fred.html"> won't.
> 
> I'll fix the sample shortly to add the +; fixing it so that it works
> with all kinds of URLs is probably much harder.
> 
> The reason that the returnVar is not set is because the regex
> extractor behaves differently for a negative match number, and does
> not set inputVar_1 to the default if no matches were found.
> 
> Thanks for reporting the problem - sorry for any inconvenience you were caused.
> 
> S.
> P.S. The regex coach is well worth investigating - see link from
> JMeter Wiki http://wiki.apache.org/jakarta-jmeter/RegularExpressions
> 
> 
> 
> On Fri, 24 Sep 2004 14:41:08 -0400, Grace Li <gr...@thespigroup.com> wrote:
> > Hi all,
> >
> > I am trying the example testplan linked in the section 'foreach
> > controller' in jmeter manual.  It is am example using the combination of
> > foreach and regex.
> >
> > I gave a link to a real html page which has several links inside. But
> > the test result shows http request failure. Looking into the response
> > data, it could be found that ${returnVar} was not set a value. It's
> > either the regular expression is not right or something else wrong.
> >
> > Can anyone shed me a light?
> >
> > thanks!
> > Grace
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: A problem while trying foreach+regex example

Posted by sebb <se...@gmail.com>.
You're right - the regex is wrong - it should be:

<a href="([^"]+)"

rather than

<a href="([^"])"

which will only match 

<a href="?"

where ? is any single character. 

Adding the + means it will match 1 or more characters (any character
except " - so that it stops when it reaches the closing "..

Fixing this allows the regex to work, however as it stands it will
only work with URLs that don't contain the host name, because the
result is used in the path field.

For example: <a href="/index.html"> should work, but <a
href="http://www.host.tld/fred.html"> won't.

I'll fix the sample shortly to add the +; fixing it so that it works
with all kinds of URLs is probably much harder.

The reason that the returnVar is not set is because the regex
extractor behaves differently for a negative match number, and does
not set inputVar_1 to the default if no matches were found.

Thanks for reporting the problem - sorry for any inconvenience you were caused.

S.
P.S. The regex coach is well worth investigating - see link from
JMeter Wiki http://wiki.apache.org/jakarta-jmeter/RegularExpressions

On Fri, 24 Sep 2004 14:41:08 -0400, Grace Li <gr...@thespigroup.com> wrote:
> Hi all,
> 
> I am trying the example testplan linked in the section 'foreach
> controller' in jmeter manual.  It is am example using the combination of
> foreach and regex.
> 
> I gave a link to a real html page which has several links inside. But
> the test result shows http request failure. Looking into the response
> data, it could be found that ${returnVar} was not set a value. It's
> either the regular expression is not right or something else wrong.
> 
> Can anyone shed me a light?
> 
> thanks!
> Grace
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org