Use JMeter Variable in Groovy Code
10,505
Solution 1
There are several of getting it:
- Given you pass the variable to the JSR223 Assertion script via "Parameters" section you can access it as
Parameters
which contains the full string passed in the "Parameters" section - Given you pass the variable to the JSR223 Assertion script via "Parameters" section you can access it as
args[0]
(if you pass more than one variable separated by spaces you will be able to refer 2nd variable asargs[1]
, 3rd asargs[2]
, etc. - You can access it as
vars.get('user')
wherevars
stands for JMeterVariables class instance - You can access it as
vars['user']
- basically the same as point 3 but uses some Groovy Syntax Sugar - You can access it as
ctx.getVariables().get('user')
- wherectx
stands for JMeterContextService class instance just in case (in some test elementsvars
shorthand is not available)
Demo:
Solution 2
Any JSR223 element including Assertion have few variables it can use out of the box.
One of the variable is vars
which is basically a map of JMeter stored variables.
User Defined Variables row is creating a JMeter variable, so you can get your value Justin in JSR223 using vars.get("user")
Author by
Justin Holze
Updated on June 12, 2022Comments
-
Justin Holze almost 2 years
I have an Config Element in JMeter, Especially User Defined Variables.
I have the variable "user" with the value "Justin", How can I use this variable in the groovy code (of an JSR223 Assertion)?