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)

3
  • 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. Commented May 14, 2012 at 11:38
  • ...You can post your solution as answer and accept it to close the issue - if you believe it's solved. Commented May 14, 2012 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 Commented May 14, 2012 at 12:29

4 Answers 4

5

You have to reference the variable with the function:

${__V(Result_${index}_g1) 
Sign up to request clarification or add additional context in comments.

1 Comment

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: stackoverflow.com/q/10626762/993246.
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) 

Comments

0

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

2 Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.