Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
When placed in the Postman 'Tests' tab, this script will unset all the variables that start with a specifically given prefix so that it's slightly different from the .clear() built-in fuction.
function cleanup() {
const clean = _.keys(pm.environment.toObject())
_.each(clean, (arrItem) => {
if (arrItem.startsWith("some_prefix")) {

This comment has been minimized.

Copy link

@nanacleto nanacleto commented Oct 15, 2019

But how you set this to run at end of the collection run?
you have a "last request" where after you run the clean variables?

It exists some way to postman knows the end of collection run?


This comment has been minimized.

Copy link
Owner Author

@DannyDainton DannyDainton commented Oct 15, 2019

I knew the what the final request was in my Collection so I have in run within there because it worked in my context.

Depends on the way that you structure your own Collections, you could have a folder that contains a request that tearsdown the data following a Collection run.

One of the Postman community members write about how he does this in his own context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment