Reputation: 425
If I use a JSR223 Preprocessor with the following code:
log.info("" + ${rand});
where ${rand}
is a random variable, how can I make this variable change every time I loop this thread?
Changing the number of threads will indeed have the variable change each run, with loop it just takes one value and keeps it for all the other loops.
Putting it in a JSR223 Sampler yields the same result. I basically want the code to behave as a User Parameter.
Upvotes: 1
Views: 771
Reputation: 58872
You need to use vars to avoid getting cached/same value
vars.get("rand")
script does not use any variable using
${varName}
as caching would take only first value of${varName
.. Instead usevars.get("varName")
Upvotes: 1
Reputation: 168157
Don't inline JMeter Functions or Variables in JSR223 Test Elements because:
They may resolve into something which will cause compilation failure
The syntax conflicts with Groovy's GStrings feature
If you tick Cache compiled script if available
box the first occurrence will be cached and used on subsequent iterations, if you don't - you will loose performance benefits of Groovy
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So:
Either move your ${rand}
variable to "Parameters" section and change your code to
log.info("" + Parameters);
or use vars
shorthand to JMeterVariables class instance, in this case change your code like:
log.info("" + vars.get("rand"));
Upvotes: 1