1

I Have API's to retrieve the token and get Positions nested under Token Generator and API Group threads.

I need to retrieve token only once and set the token to the property and access it across multiple threads.

Reponse from the post request:

{"token":"eyJhbGciOiJIUzUxMddiJ9.eyJ1c2VyX25hbWUiOiJhZG1pbiIsImxhc3RfbmFtZSI6ImFkbWluIiwiZmlyc3RfbmFtZSI6ImFkbWluIiwidXNlcl9pZCI6OCwicm9sZSI6IkFETUlOIiwiaWF0IjoxNTg2NDQ3MTc2LCJleHAiOjE1OssdDY1MzM1NzZ9.Q9-DT0q7uR53prnZFw1cTFIAlhqzj-qzNwr3qCbFn5B4irAxkR469aGxQK5VhvfEoPk4R_jZwyOpERzmVcRI6A"}

enter image description here

JSON Extractor in Token Generator thread

enter image description here

BeanShell PostProcessor in Token Generator thread

props.put("token", jwt_token); 

HTTP Header Manager in API Group thread

Authorization : Bearer ${__P(token)}

but my request headers in second API:

Authorization: Bearer 1

What am i missing here?

  • Are you running both the thread in parallelly or one after another? – Amol Apr 10 at 16:10
  • 1
    @Amol Sequentially – Karthik Suresh Apr 11 at 14:57
  • Karthik Suresh : Please see my answer. – Amol Apr 11 at 15:17
0

You need to update your code in Beanshell Post Processor.

props.put("token", jwt_token); 

You are trying to set a variable value in a property, but from the code, you have provided you are using jwt_token which is not the value extracted. You should update your code as below -

props.put("token", vars.get("jwt_token")); 
| improve this answer | |
0
  1. Don't use Beanshell, starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
  2. You can avoid this JSON Extractor bit and perform the extraction of the JWT token and storing it into a JMeter property in a single line of code to wit:

    props.put('token', new groovy.json.JsonSlurper().parse(prev.getResponseData()).token)
    

More information:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.