JMeter: how to change a user-defined variable value for a second iteration of the number of cycles

I run a thread group with the following property values:

Number of threads: 200 Acceleration time (sec): 20 Number of cycles: 2

I also have user defined variables set for HTTP requests. However, when the second iteration is achieved, I also need to change the value of the user variable.

+7
jmeter
source share
1 answer
  • Add a Beanshell Preprocessor as a child of the first request
  • Put the following code in the PreProcessor "Script" area:

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

vars is an abbreviation for the JMeterVariables instance of the class and the getIteration () method returns the current loop number.

If you want to immerse yourself in Beanshell with the device in particular and extend the JMeter test using scripts in general, I would recommend that you familiarize yourself with the BeanShell usage description : a favorite built-in component of the JMeter guide.

+7
source share

All Articles