1

I am working on a Restful API that creates a new token after each request. So, in Postman I am refreshing my token environment variable after each request in Tests like following:

  pm.test("Successfull Login Test", function () {
    pm.expect(pm.response.text()).to.include('"result":"success"');
    var res = pm.response.json();
    pm.environment.set("token", res.token);
  });

I wonder if it is possible to do this operation for all collection items? I mean I want to say to Postman, run this script after every request.

Thank you.

AbdurrahmanY
  • 809
  • 13
  • 22
  • Can you not use the pre-request script? Use this script, which is run before each script in Postman, to validate the token is set (or updated) and then set a variable (if this token is needed), and then your normal script can run and do the request and testing as you would expect? – Steven Scott Jul 06 '20 at 15:44
  • Thank you Steven. API Changes token value every time. So I need a function after got the response – AbdurrahmanY Jul 06 '20 at 16:28

1 Answers1

3

How about using a collection, and the collection (or folder) can also have tests that are run after every request. Postman Collections/Folder Testing.

Collection Pre-Request Scripting

Collection Tests

Steven Scott
  • 10,234
  • 9
  • 69
  • 117
  • Hope it works for you, with the processing order that Postman uses, but it should be able to meet your needs. – Steven Scott Jul 07 '20 at 14:44
  • 1
    Thank you Steven! This is what exactly I am looking for. Actually, I tried and wrote a comment from mobile app yesterday, but now I cant see it. I hope this comment reaches you this time :) – AbdurrahmanY Jul 08 '20 at 06:57