Run Script at End of Runner

Hello,

I am not seeing any documentation on this, so I am not sure if something like this even exists in Postman. But, is there a way to run a single cleanup script that runs once, after all selected tests are completed? Like, I see post-request scripts on a folder or a collection level, but it looks like these run after each request. I am mainly looking to clear some variables once my runner is complete, just so my next run starts in an expected state. Thank you so much for checking out this post.

Matt

Postman doesn’t have that functionality currently.

You may want to create a feature request on the Postman Support Github.

Check to see if anyone else has asked for this first though, as it sounds like something that might have been requested previously.

I don’t know what your cleanup scripts need to do, but my advice is that you should check the known/expected state before you run your request/collection, not rely on a clean-up script that may or may not have run successfully.

You could put this in the pre-request script of the first request in the collection.

In Postman, running a cleanup script after all selected tests are completed is a bit different compared to running scripts after each request. Postman’s built-in scripting capabilities allow you to run scripts after each request (pre-request and test scripts), but there’s no direct feature for a global “cleanup” script that runs once after all requests in a collection or runner.
// Example cleanup script
pm.environment.unset(“variable_name”); // Clear environment variable
pm.globals.unset(“global_variable_name”); // Clear global variable

Hi @security-administra3 :wave:.

As @michaelderekjones recommended, you can create a feature request here.

A hack for this will be to add a request to https://postman-echo.com/get at the end of your collection. You do not need the response from this request, but you can add a post-response script that resets your variables and does the cleanup.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.