4

I'm creating some tests with JMeter, the situation is very simple, I have a search page with a list of results, and I have to retrieve from this results some values to use in the next request. Those results are around 350, I don't need them all.

I used the RegexExtractor to retrieve those results and it works (I setted it to retrieve just 10 results), but now I don't know how to access the results inside a LoopCounter. The extractor put the results into a variable named Result.

The problem is that I don't know hot to build dinamically the name of a variable. Do I have to use some function like _p()?? I can access the variable just putting the static name Result_0_g1

Inside the LoopCounter I putted also a Counter to store the loop count into the variable index

Thank you

EDIT:

SOLVED I have to write:

${__V(Result_${index}_g1)

Oliver Lloyd
  • 4,936
  • 7
  • 33
  • 55
rascio
  • 8,968
  • 19
  • 68
  • 108
  • The solution given here by the OP might work in context but it won't handle no matches on the regex and is generally needlessly complicated in comparison to jmeter's built-in solution. – Oliver Lloyd May 14 '12 at 11:38
  • ...You can post your solution as answer and accept it to close the issue - if you believe it's solved. – Aliaksandr Belik May 14 '12 at 12:02
  • mm which are the built-in solution in this case? I've tried with the ForEach controller but it doesn't seem work – rascio May 14 '12 at 12:29

4 Answers4

5

You have to reference the variable with the function:

${__V(Result_${index}_g1)
rascio
  • 8,968
  • 19
  • 68
  • 108
  • You need in this case not ${__V(Result_${index}_g1) but ${__V(Result_g${index}}: if there are more than one match jmeter will generate specific variables for each match, based on the variable name to which you are trying to extract - in your case Result_g0, Result_g1, ..., Result_gN. Look into this: http://stackoverflow.com/q/10626762/993246. – Aliaksandr Belik May 18 '12 at 15:45
1

...Just for collection.
See also this post for another implementation (case without using ForEach Controller):

ThreadGroup 
    HttpSampler 
        Regex Extractor (variableName = links) 
    WhileController(${__javaScript(${C} < ${links_matchNr})}) 
        HTTPSampler use ${__V(links_${C})} to access the current result 
        Counter (start=1, increment=1, maximum=${links_matchNr}, referenceName=C)
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
0

Use the ForEach Controller - it's specifically designed for this purpose and does exactly what you want.

Oliver Lloyd
  • 4,936
  • 7
  • 33
  • 55
  • It seems that the ForEach controller don't work if I put the Match No. in the regex extractor...The problem is that I want to retrieve just the first 10 results – rascio May 14 '12 at 12:28
  • 1
    Use a match number of -1, this returns all matches and creates the groups, then you can simply limit the foreach to 10 iterations using a counter. Quote from help text: "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. " – Oliver Lloyd May 14 '12 at 12:32
0

You may use ForEach Controller:

ThreadGroup
    YourSampler
        Regular Expression Extractor (match -1, any template)
    Foreach controller
        Counter(Maximum -> ${Result_matchNr} , Rf Name -> index)
        LinkSamplerUsingParsedData(use -> ${__V(Result_${index}_g1)}

Now, if you want to iterate to all groups, you need another foreach to do that. As you know which group represent what value, you can use this way.

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
Shantonu
  • 1,280
  • 13
  • 12