0

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:

  1. JSON Extractor to get the token and store it into bearerToken variable,

  2. JSR223 PostPocessor & groovy to pass token to another thread, I wrote this ${__setProperty(bearerToken,${bearerToken})}

    JSR223 Post Processor

In Thread Group 02, I performed the following configuration:

  1. User Defined Variables, then using __property() function

    property function

  2. And use it as a header

    http 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.

view result tree

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.

Run Thread Groups consecutively

nb:I can't show the image because it needs at least 10 reputation

tim_yates
  • 167,322
  • 27
  • 342
  • 338
ilf
  • 5
  • 4

1 Answers1

0
  1. Amend your JSR223 PostProcessor code to use props and vars shorthands instead of inlining the function there:

    props.put('bearerToken', vars.get('bearerToken'))
    
  2. In your HTTP Header Manager use __P() function as

    ${__P(bearerToken,)}
    
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Hi @Dmitri T, thanks for answering my question. It's work for me, and after came across with this article about [User Defined Variables](https://jmetervn.com/2016/12/09/user-defined-variables/) I know why my setup doesn't work. I use UDF in every thread group with the expectation that it will be executed when the group thread is started. Turns out I was wrong, the UDF will be executed first -- in whatever order it's in -- when the test plan is performed. After that, I tried it directly in the HTTP Header Manager and it worked immediately. And your answer makes me even more confident. – ilf May 07 '23 at 16:01
  • The [documentation](https://jmeter.apache.org/usermanual/component_reference.html#User_Defined_Variables) is also mention about it. – ilf May 07 '23 at 16:06