1
votes

I have a question about using http request in Jmeter I created a json request. and I tried to pass parameters that I used in previous steps (I saved it using vars.put("Expected_Offer_Name").
I would like to use vars.get("Expected_Offer_Name"), as parameter, but Jmeter refuse to use this parameter.

But when I use "${Expected_Offer_Name}" it worked OK. 1. what is the difference? in both cases I Want to pass a string parameter. 2. Is their a way to use vars,get instead.

[Not working][Not working]

[enter image description here][Working]

Is their a way to use vars.get in the json's http request

2

2 Answers

2
votes

You can't use vars in HTTP Request.

vars is a special variable only for scripting which is available only in:

  1. JSR223 Elements scripts

Before invoking the script, some variables are set up. Note that these are JSR223 variables - i.e. they can be used directly in the script.

  1. Beanshell/groovy Elements or functions.

It's also added for getting variables using the right way:

ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use : vars.get("varName")

In other locations you need to get variable using ${varName}

1
votes

Wrap your vars.get("Expected_Offer_Name") into __groovy() function like:

${__groovy(vars.get("Expected_Offer_Name"),)}

JMeter Groovy Function

You can use JMeter Functions anywhere in your Test Plan.

NB: you need JMeter version at least 3.1 in order to use __groovy function