0

JWT Token(having fix time duration(about 1 hr)) is needed inside Header of Postman to test Rest-apis. How to automate such test cases if it require token having fix time duration. I have written approx 30 test cases,if I run my test cases using Collection runner inside Postman, most of the test cases will be failed,because it does not include fresh tokens inside each test cases.

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Anil
  • 1
  • 4

1 Answers1

0

Regarding your scenario, why don't you follow:

  1. Execute your auth request as the first call
  2. Get the access token
  3. Store it in an environment variable
  4. Use the token in subsequent requests where you need it.

This will make sure all your request have access token generated on run time.

For more info, refer > http://blog.getpostman.com/2014/01/27/extracting-data-from-responses-and-chaining-requests/

Dinesh Kumar
  • 1,694
  • 15
  • 22
  • Got it, thanks.But I stuck at another issue,I need to change UserId (into url) dynamically, response is in JWT token, from previous api,I can write somthing into pre-request script of current api to fetch UserID from the response(JWT token) coming from previous Api. How can I achieve this without using any library. – Anil Jun 30 '17 at 04:55
  • Postman has limited set of available libraries, I'd look for web service that can extract this for you, and incorporate call to it after authentication one. – klubi Jul 02 '17 at 13:22
  • Can you take the UserId in the JWT response and set that as an environment variable to use in the URL of another request? – Danny Dainton Dec 28 '17 at 13:01