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?

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

2 Answers 2

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")); 
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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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