Is there a way to run the middle iteration In Postman

My question:

I have a CSV file which has Create, Edit, Search & Delete functionality in one CSV file. When i run it via postman for all the records created it executes, Create then Edit, then Search and Delete. I don’t want every test to be edited, I want only few. Is there way where i can tell it should run on that particular test case for Edit. Kindly reply

How I found the problem: When i ran the CSV all the 17 iteration does create, search, edit and delete

I’ve already tried: I am unable to figure out how to do.

I’m not sure exactly how your tests are structured - do you have separate folders for Create, Edit, Search and Delete?

Regardless, it may be useful to know that the request info object allows you to determine which iteration (i.e. which CSV row) is currently being tested.

For example, here is a dummy test which would only run on the 10th-15th rows of your CSV file:

if(pm.info.iteration >= 10 && pm.info.iteration <= 15) {
    pm.test("Hello world", function () {
        console.log("Running test on iteration " + pm.info.iteration)
        pm.expect(1).to.equal(1)
    });
}

(Depending on how your tests are structured, you may choose to put this “if” block somewhere different; e.g. you might wrap it around your entire set of tests, or you might set the iteration count check into a boolean so that you can repeatedly reference it with less code)

However, this relies on your source data structure never changing, and might be difficult to maintain. If you have control over your CSV file, it might be beneficial to add an extra column called (for example) TestsToRun and set the value to whichever tests you want to run, for example:

Account,Name,TestsToRun
123,John,CreateEditSearchDelete
199,Joe,CreateEditSearchDelete
250,Jim,CreateSearchDelete
999,Jack,CreateSearchDelete

Then instead of checking the iteration number, you can just check the value of TestsToRun for this iteration to determine whether to run the test:

if(pm.iterationData.get("TestsToRun").includes("Edit")) {
    pm.test("Hello world", function () {
        console.log("Running test on iteration " + pm.info.iteration)
        pm.expect(1).to.equal(1)
    });
}

In this way it would be easier to review your CSV in the future, remember which tests are running for each iteration, and make changes to which test cases are running without having to make further script modifications.

Thank you Niel,

I want to run create, Search, Edit & Delete together.

I have made my CSV file in such manner.

When I return it. It runs 17 times for Create, then 17 times for Search, then 17 times for Edit & 17 times for Delete.

How do I tell it when running together this should not be run for Edit or delete. Is there a way.

@parijosh I see, so you want to completely skip the execution of Edit & Delete for certain iterations?

In that case, you could add a test such as the below, at the bottom of your Search tests. By using setNextRequest(null), it tells the current iteration to not run any further tests, so the Edit & Delete tests will not be run.

if(pm.info.iteration >= 10 && pm.info.iteration <= 15) {
    console.log("Skipping Edit/Delete for iteration #" + pm.info.iteration);
    postman.setNextRequest(null);
}

Thank you Neil


This is my reacord to create, edit search, delete,

In this I want only the success response to do edit, Delete.

In one excel I am performing create delete, edit, search.

This is just one file.

I have like this more than 100 file. If I give the iteration number it will only work for 1 CSV. How about others

Hi @parijosh,

That data really helps, thanks! I can’t quite see the name of column AJ (“response-something”) but if you only want to run Edit/Delete tests when this column contains the value SUCCESS, you could try this at the end of your Search tests (change “response-something” to the actual header of column AJ):

if(!pm.iterationData.get("response-something").includes("SUCCESS")) {
    console.log("Skipping Edit/Delete for iteration #" + pm.info.iteration);
    postman.setNextRequest(null);
}

In other words: If column AJ does not contain the word SUCCESS then do not run any more requests for this scenario.

Thank you Neil,

It only wrote in the console, in actual it did not skip.

One more image to the above one

Niel, Can you please reply