Unable to send the value extracted from Json extractor as a body parameter for another http request in different thread in jmeter

Viewed 36

I am trying to fetch a value from a json response using Json extractor and use that value as a body parameter for the next http request which is in another thread group.

I am able to fetch the value in debug sampler but when i use the solutions provided on the net to pass the value then nothing is getting picked.

Also my 1st request accepts the body in form-data format and the 2nd accepts the datavin raw format.

Attaching the screenshots below for better understanding:

drs_id captured in debug sampler of the 1st thread group: DRS captured

Json extractor settings in the 1st thread group: Json extractor

Bean shell post processor

Tried two ways to get the value in the 2nd thread group in the body: Body of the 2nd request in another thread group

In the request body drs_id is not getting picked up request body is not getting the value of drs_id

2 Answers

I would suggest instead of Beanshell postporcesser use Beanshell Assertion. With your example I am able to pass it,

DRS_ID Fetched

enter image description here

Set is as Property Variable in Beanshell Assertion

enter image description here

Pass the value in second thread group, enter image description here

enter image description here

Using you method,

enter image description here

enter image description here

Be aware of JMeter Scoping Rules

If you add JSON Extractor and Beanshell PostProcessor at the same level as 1 or more Samplers - the PostProcessors will be executed after each sampler

In your situation:

  1. JSON Extractor is executed after DRS Creation sampler - here the variable is extracted and set
  2. Then JSON Extractor is executed after Debug Sampler, there is no match found hence you're getting default empty value

So you need to either remove/disable the Debug Sampler or put your JSON Extractor and Beanshell PostProcessor to be the direct children of the DRS Creation sampler


Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so it worth considering migrating. More information: Apache Groovy: What Is Groovy Used For?

Related