Same test multiple API endpoints

I have multiple APIs which have same response format.
I want to be able to run that same test on multiple APIs.
I don’t want to go to each API endpoint and write the same test in tests tab of Postman.
Any soultion for this!!

Hey @satellite-pilot-5611 :wave:

Welcome to the Postman Community! :postman:

You can write the test at the Collection level and that will run against each request. This can also be done at the Folder level too, just in case some of the request return a different format and you need to seperate them out.

As an example, this test at the Collection level would run each time you send a request to check the status code:

1 Like

Thank you so much, I have been searching for a solution online for atleast 2 hours. I got the answer from here within an hour. :grinning:

Happy to help! :trophy:

I would also recommend taking a look through our learning centre (Direct link to this in the header bar on the right).

We have various sections which cover the core functionality of the platform as well as links out to other helpful resources.

Here’s more about the scripts and the execution order:

1 Like

I have wrote a test at the folder level, but now I want that test not to be applicable for a particular endpoint.

When we run the folder we can skip a particular endpoint, but if we automate the testing process how to skip that end point.

I need to see what you’re doing to “skip” the endpoint. I don’t know what you have in front of you :smiley:

From a very basic point of view, you could just tell it to only run the test if the request doesn’t match:

if(pm.info.requestName !== "Request_Name") {
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });
}

It could also be something like this if you need to show a test is skipped for the request:

let skipTest = pm.info.requestName === "Request_Name";

(skipTest ? pm.test.skip : pm.test)("Check status code", () => {
    pm.expect(pm.response.code).to.equal(200);
});
1 Like

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