user1582114
user1582114

Reputation: 199

JMeter - loop controller with variable loop count

I am using JMeter and I want to define one loop controller. In this loop I want to define the loop count with a Jmeter variable. Is this posible?

Thanks a lot

Upvotes: 19

Views: 53592

Answers (3)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34526

Yes, it's possible.

Define your user variable using the User Defined Variables component, or use the CSV component.

Then, in the Loop Controller, define loop count to: ${nameOfVar}

Since version 4.0 of JMeter, there is an easier way:

JMeter will expose the looping index as a variable named

__jm__Name of your element__idx

So for example, if your Loop Controller is named LC, then you can access the looping index through ${__jm__LC__idx}. Index starts at 0

If you're looking to learn jmeter correctly, this book will help you.

Upvotes: 17

Graham Russell
Graham Russell

Reputation: 1047

You can use the following inside the "Loop Count" field:

${myVar}

e.g. for a random count:

${__groovy(java.util.concurrent.ThreadLocalRandom.current().nextLong(128L),)}

You can access the current loop index (starts at 0) via ${__jm__Loop Controller__idx} where Loop Controller is the name of your loop.

Upvotes: 3

Johnny Willer
Johnny Willer

Reputation: 3917

I know is very late to help you, but it can help the others.

One good way to do this is to define a counter inside the loop controller.

Example, if you want a loop with 20 iterations, you put 20 in the loop controller and in the counter you put from 0 - 19. In the counter you can also define an increment. The output variable is named in the Reference Name field.

loop controller with counter

Upvotes: 20

Related Questions