Search code examples
groovyjmeterjsr223

The looping index returns 0 resolved during execution in a JMeter Loop Controller


I have a problem with the looping index for a looping controller. I have a loop named exampleLoop and are accessing the looping index from inside the loop with a JSR223 sampler using groovy.

My code in the JSR223 Sampler:

log.info("Iteration nr: " + vars.get("__jm__exampleLoop__idx"))

When executing the loop 5 times I get:

Iteration nr: 0

Iteration nr: 0

Iteration nr: 0

Iteration nr: 0

Iteration nr: 0

It seems like the looping index is caching the first value(Starting value 0). Do anyone know how to get the looping index variable to be updated every iteration iteration so that I will get the following print out:

Iteration nr: 0

Iteration nr: 1

Iteration nr: 2

Iteration nr: 3

Iteration nr: 4

I have tried to enable and disable the "Cache compiled script if available" option but no change.


Solution

    1. The value will be incremented during each iteration caused by the Loop Controller, iterations of the Thread Group or other Logic Controllers will not be taken into consideration (or you will have to refer them using their own names, the JMeter Variables with their respective values can be visualized using Debug Sampler and View Results Tree listener combination)

      enter image description here

    2. Make sure that your Loop Controller is named as exampleLoop

    Demo:

    enter image description here