for a relatively large API test project (about 1000 requests) i need a generic way to access the folder name of any request in the test scripts. Due to the high effort hard coding the folder names manually is not an option.
Outside of creating a Collection object, there isn’t a Sandbox method for getting folder name right now (but we do have an open feature request for it)
How many folders are you dealing with? What about this:
In each folder, add a pre-request script that sets a local variable with the name of the folder. You’d have to hard-code the folder name value, but if you don’t have a ton of folders this could work:
Folder A —> Pre-request script —> pm.variables.set('folder_name','Folder A');
Then, any script in your Collection can access the current folder name by using: pm.variables.get('folder_name');
When the Collection run moves to the next folder, that folder would (ideally) contain the same script, but with it’s own value.
Hi, sorry for the long delay of my response have been to vacation.
Your suggested approach did the trick for me. I have added a Pre-Requests-Script to each folder (about 20) and wrote the required info to a temp var.
In my tests I have then used it to write the folder name into the test results like this:
var folderID = pm.environment.get('folderID');
pm.test(folderID, function () {
});
Thank you for your input However a native feature still would be great
Come on! just make it already
I wish postman had some really good competition out there so they’ll get back to developing stuff for the users instead of changing themes every month.