Run specific testcases only once in a iteration

I have a collection which has 4 testcases. first 2 are related to token generation and other one is a negative testcase which should be running only once. The remaining 2 testcases accepts data from CSV and should run for all iterations. I tried all the solutions provided in the community but still it did not work. Can someone please provide me a solution?

Testcase run - Iterations

First of all, you have four requests, not four tests.

Each of those post requests could have a single test, multiple tests (or none at all).

Now we’ve got that out of the way.

When you run this with the collection runner and data file, it will run the entire collection for each line in the CSV.

For the work flow you are describing, I can think of two options.

  1. Move the Authorization and No Input requests to a pre-request script using the Postman sendRequest() function. You will need to initialize a variable to determine whether the request has already run or not, and then use conditional logic (an IF statement) to control whether you need to send the request or not.

  2. Keep the requests as they are but use the skip request feature to skip the request if its already been run. (You will again need to initialize a variable to determine whether the request has run or not).

Optimize Your API Testing Workflow with Postman’s Skip Request Feature | Postman Blog

The New Skip Request Feature - :newspaper: Postman News - Postman Community

1 Like

Thanks Mike. For the second case is there any sample code available where we are checking whether the testcase is already executed. If so please let me know so that it will be helpful for me to refer.

Not as far as I’m aware.

There is a method available to called iterationCount that you can probably use without setting a specific variable.

The iteration count starts at zero, so your IF statement just needs to check if is more than zero and skip the request if it does.

It won’t tell you if the request was executed (successfully or otherwise) during iteration zero.

If you need to check that, then you will need to set a collection variable in the tests tab for each of those requests and then include that in your IF statement.


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