Reputation: 181
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)?
Upvotes: 10
Views: 18545
Reputation: 168147
There are several of getting it:
Parameters
which contains the full string passed in the "Parameters" sectionargs[0]
(if you pass more than one variable separated by spaces you will be able to refer 2nd variable as args[1]
, 3rd as args[2]
, etc.vars.get('user')
where vars
stands for JMeterVariables class instance vars['user']
- basically the same as point 3 but uses some Groovy Syntax Sugar ctx.getVariables().get('user')
- where ctx
stands for JMeterContextService class instance just in case (in some test elements vars
shorthand is not available) Demo:
Upvotes: 13
Reputation: 58862
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")
Upvotes: 3