Reputation: 21096
I have a ForEach controller in JMeter.
How can I access counter of a loop inside this controller (through variable) and then use it for creating new variables?
Upvotes: 13
Views: 16980
Reputation: 2303
No need for a counter.
The loop index is built into JMeter 4.0 and later - see Jmeter/Groovy: getting iteration number without reference to Beanshell
Jmeter bug 61802 - Loop / ForEach Controller should expose a variable for current iteration
For example if your ForEachController is named ForEachCard then this will get you the loop index (starting at zero).
def cardIndex = Integer.parseInt(vars.get("__jm__ForEachCard__idx"));
This would get you the ordinal and then obtain the associated value from a previous JSON Extractor using capture all ( Match# = -1 )
def cardOrdinal = Integer.parseInt(vars.get("__jm__ForEachCard__idx")) + 1;
def currCardBalance = vars.get("cardBalance_" + cardOrdinal )
Upvotes: 1
Reputation: 1
I have used this ForEach controller in my script and I got the answer. First create a regular expression for the value you are looking for and then add a ForEach controller
With the above image you will get a clear idea about it.
Upvotes: -1
Reputation: 21096
Put Counter configuration element inside ForEach Controller and check attributes "Track Counter Independently for each User" and "Reset counter on each Thread Group Iteration"
Upvotes: 12