19

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

2
  • Hello, was answer below the right one, if not which one is it ? Thanks Commented Aug 12, 2012 at 12:15
  • The correct one is stackoverflow.com/a/11852314/460802 Commented Aug 26, 2017 at 8:23

3 Answers 3

20

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

Sign up to request clarification or add additional context in comments.

Comments

18

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.

2 Comments

Too complicated
Yes, that's why Philippe M. member of our team introduced the way you mention bz.apache.org/bugzilla/show_bug.cgi?id=61802. I updated this answer which is pre 4.0 :-)
3

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.

1 Comment

I gave you +1 since it's correct, WITHOUT even using the groovy script which does nothing here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.