1
votes

I have a JMeter test that has a rest sampler that outputs a value as such in the response data:

{"Var1":"xxxxx-xxxxxxxx-xxxxxxxxxx"}

I need to take that out put (Var1) and use it as input for the next rest sampler in the following test step. I have a line in a BeanShell pre-processor that says:

String clearText = "somestring1" + "_" + var1 + ":" + "somestring2";

where var1 is derived from a Regular Expression Extractor from the preceding RestSampler (that is how I got the out put {"Var1":"xxxxx-xxxxxxxx-xxxxxxxxxx"} ).

Problem: I get a void for var1 in the output of the second rest sampler.

What am i doing wrong? how can i get the value from the output of the first rest sampler and use it as input in the second rest sampler??

Thanks.

ironmantis7x

2
Check jmeter logs for any error. Use debug sampler to see what are your other variables. Provide your test plan and logs.Manish Sapariya

2 Answers

2
votes

Are you sure that your Regular Expression Extractor is correctly obtaining Var1? If you're testing RESTful API it's better to use JSON Path Extractor available via JMeter Plugins (you will need Extras with Libs Set).

Configure JSON Path Extractor as follows:

  • Reference Name: Var1 or whatever you like
  • JSON Path: $.Var1 this one assumes your response.

So you would be able to provide the variable value as ${Var1} or ${__V(Var1)} to 2nd request.

See Using the XPath Extractor in JMeter (Scroll down to "Parsing JSON") for more details on how to properly install the extension and build up JSON Path queries.

Hope this helps.

0
votes

If your API returns response in JSON format then use below solution :

#1 To use this parameter within same thread group:- a] Right click on Thread Name --> click on "Add" --> click on "Post Processors" --> select "Json Extractor"

b] On 'Json Extractor" window, select below values : Variable Names == test //give any variable name(user-defined) JSON Path expressions == $.[0].name //this will pick value of "name" param from API's Json response

c] Now to use ${test} to pass this value to other API as input. By using ${test} you can use it anywhere.

#2 To use this ${test} parameter in other thread group :- a] Right click on Thread Name --> click on "Add" --> click on "Post Processors" --> select "Json Extractor"

b] On 'Json Extractor" window, select below values : Variable Names == test //give any variable name(user-defined) JSON Path expressions == $.[0].name //this will pick value of "name" param from API's Json response

c] Right click on First Thread Name(where variable value is populated) --> click on "Add" --> click on "Assertions" --> select "BeanShell Assertions"

d] Under "script" section paste below code : ${__setProperty(test, ${test})};

e] Now you can access this first API's response value using ${__property(test)} variable