Search code examples
postman

Obtain folder name in test script


I'm writing API tests using Postman. I'm organizing them into folders by endpoint, and subfolders by test cases within the endpoint folders. There are multiple cases for each endpoint and for each case there are post calls that set up data prior the the csubject-endpoint call that I'm making assertions against.

I already have 100s of calls in this suite. The test runner, unfortunately, does not provide the folder names in its output, so it's difficult to see at a glance which particular case I am looking at when, for example, it reports a test fail.

Is there a convenient way to obtain the folder names for a given call in its test script? With this, I could prepend the case name to the test name, and that would make my tests vastly more readable.


Solution

  • I don't think that there is anything like that from within the application - The closet I can see is the pm.info.requestName function which references the request name that the test belongs too.

    This is a basic use case but you could add this to the test name to give you a 'quick glance' and what was run against what request.

    pm.test(`${pm.info.requestName} - Status code is 200`, () => {
        pm.response.to.have.status(200)
    })
    

    enter image description here

    If you take a look at Newman it might have something within the summary object that you could extract, in a script, to get the folder name but I've never done this.