postmanpostman-collection-runnerpostman-testcase

Is there any way to run a test script after each request in Postman Collection?


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.


Solution

  • 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