jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kyle McAbee" <k.mca...@treev.com>
Subject RE: Can number of regular expression matches be tested ?
Date Wed, 13 Oct 2004 20:55:09 GMT
Dear sebb and JMeter Users:

sebb explained that an If Controller element will not stop the test plan, because the If Controller
affects only its child elements, not all elements "below" it. (Thank you, sebb.)

Following sebb's suggestion to explore regular expressions again, I developed the workaround
below. Is there is a better solution?

To test for an exact number of regular expression matches that may occur anywhere in the HTTP
response text, add two Response Assertion elements under the HTTP Response element.

1. In one Response Assertion element, use a regular expression that detects an exact number
of matches in the HTTP response text. Set the Pattern Matching Rules option to Contains. For
example, to detect exactly two matches of "target":

[\W|\w]+(target)[\W|\w]+(target)

This Response Assertion will stop the test plan if the HTTP response text contains fewer than
the exact number of matches. 

2. In another Response Assertion element, use a regular expression that detects the exact
number of matches PLUS ONE in the HTTP response text. Set the Pattern Matching Rules option
to Not. For example, to detect three matches of "target":

[\W|\w]+(target)[\W|\w]+(target)[\W|\w]+(target)

This Response Assertion will stop the test plan if the HTTP response text contains more than
the exact number of matches.

The refName_matchNr variable contains the number of matches extracted by a Regular Expression
Extractor element. For future reference:

1. Is there a way to compare the value of refName_matchNr variable to a desired number to
control test plan execution other than by using an If Controller element?

2. Does the __regexFunction create a refName_matchNr variable? (Section 16.5.1 in the user
manual does not say it does.)

Sincerely yours,

Kyle

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com]
Sent: Tuesday, October 12, 2004 6:20 PM
To: JMeter Users List
Subject: Re: Can number of regular expression matches be tested ?


On Tue, 12 Oct 2004 17:16:01 -0400, Kyle McAbee <k.mcabee@treev.com> wrote:
> Dear JMeter Users:
> 
> Is there a way to test the number of matches extracted by a Regular Expression Extractor
element?

Yes, the xxx_matchNr  variable

> The following code works. Unfortunately, it ALWAYS works. I used a regular expression
tester to make sure that the target string occurs 4 times in the HTTP response text. If I
understand the manual, when the condition in the If Controller evaluates to false, the test
plan should stop. So specifying the wrong number of matches in the condition should stop the
test plan. But it does not.

The If controller only controls whether or not its children are
invoked. It does not stop a test, nor does it set the status of the
sampler to failed.
 
If you can work out the appropriate regex, you could use the Regex
Assertion to mark the sample as failed, and cause the test to stop
that way.

> HTTP Request
>   Regular Expression Extractor element
>     Reference Name: Matches
>     Regular Expression: string
>     Template: $1$
>     Match No: 1
>     Default Value: NoMatches
> 
>   If Controller element
>     Condition: Matches_matchNr == 4

This means to invoke any child samples of the If controller
 
> Sincerely yours,
> 
> Kyle
> 
>

---------------------------------------------------------------------
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


Mime
View raw message