The Jmeter I am using is version 5.5, I want to pass the token generated by Thread Group 01, to Thread Group 02. After doing some research, I know how to do it, but it always fails at the first try.
In Thread Group 01, I performed the following configuration:
JSON Extractor to get the token and store it into bearerToken
variable,
JSR223 PostPocessor & groovy to pass token to another thread, I wrote this ${__setProperty(bearerToken,${bearerToken})}
In Thread Group 02, I performed the following configuration:
User Defined Variables, then using __property()
function
And use it as a header
Every time it is run for the first time, the http-request in Thread Group 02 always fails to run because it doesn't get a token. But if it is run again for the second time, it will succeed.
The yellow box is the first time Thread Group 01 (Login & Debug Sampler) and Thread Group 02 (Index) are run, the blue box is the condition when run for the second time.
I thought initially Thread Group 02 was run first before Thread Group 01, that's why I enabled the "Run Thread Groups consecutively (i.e. one at a time)" option in the Test Plan. I ran it and checked the listener, the result was the same, Thread Group 01 (Login & Debug Sampler) was successfully run but Thread Group 02 (Index) was not successful because it did not get an access token.
nb:I can't show the image because it needs at least 10 reputation
Amend your JSR223 PostProcessor code to use props
and vars
shorthands instead of inlining the function there:
props.put('bearerToken', vars.get('bearerToken'))
In your HTTP Header Manager use __P() function as
${__P(bearerToken,)}