Last active
October 15, 2019 13:23
-
-
Save DannyDainton/0a204d53e72464029a5aca8b2ae1592f to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cleanup() { | |
const clean = _.keys(pm.environment.toObject()) | |
_.each(clean, (arrItem) => { | |
if (arrItem.startsWith("some_prefix")) { | |
pm.environment.unset(arrItem) | |
} | |
}) | |
} | |
cleanup() |
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.
https://community.getpostman.com/t/my-code-snippets-from-the-london-postman-summit-paul-farrell/4591
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
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?