Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter: How to change user defined variable value for second iteration of loop count

Tags:

jmeter

I'm running a Thread Group with the following property values:

Number of threads: 200 Ramp-up Time (sec): 20 Loop-count: 2

I also have user defined variables set for the HTTP Requests. However, when the second iteration is reached, I need the user defined variable's value to also change.

like image 575
DanzerZoneJS Avatar asked Sep 25 '14 12:09

DanzerZoneJS


1 Answers

  1. Add a Beanshell PreProcessor as a child of first request
  2. Put the following code into PreProcessor's "Script" area:

    if (vars.getIteration() == 2) {
        vars.put("myVar", "newValue");
    }
    
  3. Replace myVar with your variable name and newValue with variable value for the second loop.

vars is a shorthand for JMeterVariables class instance and getIteration() method returns current loop's number.

If you want to dive deaper into Beanshell in particular and extending JMeter test via scripting in general I would recommend to get familiarized with How to use BeanShell: JMeter's favorite built-in component guide.

like image 56
Dmitri T Avatar answered Sep 20 '22 16:09

Dmitri T