You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by MA <ma...@gmail.com> on 2008/01/18 00:25:22 UTC

RE: Foreach loops with groups

This was an old post but replying because it might be useful for anyone who
wants to use it.

The easiest way I could get all the variable values in ForEach Controller
with more than one group was

1) Since ForEach needs a regular expression with Match number negative(say
-1)
    eg. the sample html code that needs processing is as below
                  <for label="jmeter">Jmeter</label>
                   <for label="user"> User </label>
----
Use the postprocessor -> regular expression extractor
the var is inputVar
the regular expression is <for label=(.+)>(.+)</label)
Match Number is -1

Loop Controller
   set the loop variable to the number of matches returned by
${inputVar_matchNr}
  Add a pre-processor element counter with start value 1 and increment 1  -
as a child to the loop controller
 Add a ForEach Controller as  a  child to Loop Controller after the counter 
    input variable -  inputVar_{C}_g
    return variable - returnVar
    Add "_" before number - uncheck

 Now ${returnVar} returns jmeter,Jmeter,user,User  all variables in all
groups. 
 ---------------------

            


Friedl, Justin wrote:
> 
> sendRequest appears once for every row in an html table.  I want to
> exercise
> (an HTTP sample) for every link in the table.  Therefore I want to extract
> three values for each call to sendRequest and pass those into an HTTP
> request.
> 
> 
> Docs:
> "By omitting the "_" separator, the ForEach Controller can be used to loop
> through the groups by using the input variable refName_g, and can also
> loop
> through all the groups in all the matches by using an input variable of
> the
> form refName_${C}_g, where C is a counter variable."
> 
> This is confusing to me?  To access group 1 of a variable in a for each
> loop
> what do I do? ${synopticDataOut_${C}_g1}?  A variable inside a variable
> doesn't seem to work.  What is C?  Is that the name of a counter that I
> added as a child of the for each loop?  That doesn't seem to work either.
> Or maybe it's an implicit counter? Also, by omitting the "_" separator the
> for each loop is never entered, (see below).
> 
> 
> I appreciate your help,
> Justin
> 
> 
> 
> -----Original Message-----
> From: sebb [mailto:sebbaz@gmail.com] 
> Sent: Tuesday, September 06, 2005 3:34 PM
> To: JMeter Users List
> Subject: Re: Foreach loops with groups
> 
> 
> On 06/09/05, Friedl, Justin <JF...@cdgnow.com> wrote:
>> Here's what I have:
>> 
>> Regular Expression Extractor
>> 
>> reference name: synopticDataIn
>> Regex: .*sendRequest\((\d+),(\d+), '(\d+-\d+).*
> 
> You probably don't need .* before and after.
> 
>> template: $1$
>> Match No.: -1
> 
> Do you really want all matches?
> How many times does sendRequest appear?
> 
>> Default Value: fout
>> 
>> ForEach controller
>> Input variable prefix: synopticDataIn
>> Output variable name: synopticDataOut
>> Add "_" before number: checked
>> 
>> then looking at the request tab in the view Results Tree the 
>> parameters
>> become:
>> ${synopticDataIn_1_g1} becomes 11479239
>> ${synopticDataIn_1_g2} becomes 1529
> 
> OK.
> 
>> ${synopticDataOut_g1} becomes ${synopticDataOut_g1}
> 
> ForEach only sets _one_ variable, i.e. ${synopticDataOut}
> 
>> ${synopticDataOut} becomes 11479239
> 
> ForEach sets ${synopticDataOut} to ${synopticDataIn_1},
> ${synopticDataIn_2},
> etc. These are the values of $1$ for each match. Is this what you wanted?
> 
> From the doc:
> 
> "By omitting the "_" separator, the ForEach Controller can be used to loop
> through the groups by using the input variable refName_g, and can also
> loop
> through all the groups in all the matches by using an input variable of
> the
> form refName_${C}_g, where C is a counter variable."
> 
> These are wrong - ForEach only sets ${synopticDataOut} 
>> ${synopticDataOut_1_g1} becomes ${synopticDataOut_1_g1} 
>> ${synopticDataOut_g1} becomes ${synopticDataOut_g1}
> 
>> 
>> if I switch the template to $0$
>> ${synopticDataOut} becomes  # 
>> onClick="processLoading(parent.parent.searchResults);
>> sendRequest(11479239,1529, '21-00'); 
>> parent.parent.swapFrame('searchResults');">
>> ${synopticDataIn_1_g1} becomes 11479239 ${synopticDataIn_1_g2} becomes 
>> 1529
>> 
>> I cannot figure out the proper syntax.  I thought 
>> ${synopticDataOut_g1} should work.  Any ideas? Examples?
> 
> No, it won't work.
> 
> See above and the documentation for RegexExtractor and ForEach.
> 
>> 
>> Thanks in advance,
>> Justin
>> 
>> 
>> 
>> -----Original Message-----
>> From: sebb [mailto:sebbaz@gmail.com]
>> Sent: Wednesday, August 31, 2005 4:09 PM
>> To: JMeter Users List
>> Subject: Re: Foreach loops with groups
>> 
>> 
>> Yes, the foreach loop won't start if the first variable is missing.
>> 
>> What do your Regex and ForEach test elements look like now?
>> 
>> S.
>> On 31/08/05, Friedl, Justin <JF...@cdgnow.com> wrote:
>> > Thanks. I tried this.  Now it won't even go into the foreach loop. 
>> > My guess is it's because the foreach input var doesn't match the 
>> > regex reference name.
>> >
>> >
>> >
>> >
>> >
>> > -----Original Message-----
>> > From: sebb [mailto:sebbaz@gmail.com]
>> > Sent: Wednesday, August 31, 2005 10:21 AM
>> > To: JMeter Users List
>> > Subject: Re: Foreach loops with groups
>> >
>> >
>> > Try
>> >
>> > ForEach:
>> > Input:    RegexVar_g
>> > Output: outputVar
>> > Add '-':  unchecked
>> >
>> > and refer to
>> >
>> > ${outputVar}
>> >
>> > S.
>> > On 31/08/05, Friedl, Justin <JF...@cdgnow.com> wrote:
>> > > I have a regular expression that returns three groups: 
>> > > .*sendRequest\((\d+),(\d+), '(\d+-\d+).* I then have a foreach 
>> > > controller in which I map input var "inputVar" to output var 
>> > > "outputVar" with the "add '_' before number" checked.
>> > >
>> > > How can I access variables in a sample controller within the 
>> > > foreach loop? I've tried: 
>> > > ${outputVar_g1},${outputVar_1},${outputVar1},${outputVarg1},${outp
>> > > ut
>> > > Va
>> > > r_g1_1
>> > > },${outputVar_1_g1}
>> > > Nothing seems to work.   The result view tree shows the sample is
> being
>> > > called but the params output the literals and don't seem to replace
> the
>> > > variables with values.
>> > >
>> > > I'm using jmeter 2.1 and I see in the changes that "ForEach 
>> > > Controller can now loop through sets of groups" was fixed in 2.0.3
>> > >
>> > > I'm sure I'm missing something simple.
>> > >
>> > > Thanks in advance,
>> > > Justin
>> > >
>> > >
>> > >
>> >
>> > --------------------------------------------------------------------
>> > -
>> > 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
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Foreach-loops-with-groups-tp753804p14937769.html
Sent from the JMeter - User mailing list archive at Nabble.com.


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