CSV Data files for multiple requests within one collection

Hi,

I am new to postman collections and runner. I have a requirement something like the following -

  1. I have multiple end to end tests within one collection. Each test is a folder with multiple requests within.

  2. I want to pass one csv datafile that has data for all the four end to end tests to the runner. The data file has 5 rows. One for the headers and four for the four tests.

  3. I want Test 1 to pick data from Row 2, Test 2 to pick data from Row 3… so on and so forth

  4. I want to execute Test1, Test2 and Test3 (not Test4) in one go.

Could you please let me know if this is possible and how to accomplish this?

Thank you,
Amruta

1 Like

Hey @amruta.kale. That is a common use case and is supported by the app. Look at this thread Running a request multiple times with different data sets, it might help you get started in the right direction.
Your 4th point can be handled by using postman.setNextRequest(null). Read more about conditional workflows here. https://www.getpostman.com/docs/v6/postman/scripts/branching_and_looping

Feel free to reply here in case you are stuck and need further assistance.

Thank you @deepak.pathania

My requirement is a little bit different from what’s mentioned in the thread you provided.
I don’t want to run the same test multiple times with different data.
I want a single data file to contain data for multiple different tests - Test1, Test2, Test3 etc in my example above. Any pointers?

Thanks,
Amruta

Hey @amruta.kale, sorry for misunderstanding your use case. On revisiting the question, I realized that this is not currently supported directly in the app but here is a small workaround that might help.

You can pass the csv data file in the pre-request script of your first request or create a dummy request for this. Now you can try parsing the csv file and store different rows as different global variables as per the use case. In each test, you can access the stored data from the global variable and use it in that particular test. This will require additional parsing and fetching logic on your end but might help in your use case.

Hope this helps.

I have got a similar requirement.
TestCase 1 wants to use Row1, TestCase2 wants to use Row3. All this has to happen in a single iteration. Any advancement in postman till now on this?

I have similar requirement and I couldn’t find a way to do it using the app. Basically, if your using data file with 4 rows. All your request update the collection will run for all the data. No way of associating a row in a file with a specific request.

I am also facing similar issue. Did anyone got resolution

you can store the content as environment variable and then use

The Collection Runner will use the values in each non-header row of a CSV as a set of variable values for a single iteration. If you only want one iteration of the collection, you only need one row. To model this appropriately for the Collection Runner, you’d have to put all test case data in the same row with different column names to differentiate between test cases.

Hope this helps.

Best,

Kevin

Hi ,

But it will not resolve my Proble. I have 20 request in my collection. all 20 requests need different data. Each request need around 10 variables to pass.

Using this method, you’d have to use 200 columns and 1 row. Each request, would use a different column name for the data (e.g., user_id_1, user_id_2, user_id_3).

Another option is play with postman.setNextRequest to conditionally execute requests based on some kind of test case ID column. Basically, if test case ID is 1, run this next request. If test case ID is 2, run that next request. It’s quite a bit more complex.

Hi again. I put together an example of how this might work. I put it in a workspace I intend to make public, but I’m waiting on my Community Manager to accept it. In the meantime, here’s a public link to a collection you can import: https://www.getpostman.com/collections/a8d2dae91fb30a757e48.

Here are the instructions included in the collection. Let me know if you have any questions!


When using a CSV data file in the Collection Runner, each row executes as a new iteration of the collection with each column in that row acting as a set of test case variables. This isn’t always ideal.

When we want to use subsets of test case data for different groups of requests in a Collection Run, one option is to inspect a field in the test case data and use that to route to different requests in our collection. We can do this with the postman.setNextRequest() function.

In this example, the Initialize folder contains a single request that acts as a Test Case router. Look at the Tests tab in that request to see how it works.

In this case, we are only using a single request for each row of test case data. However, you could use multiple. Look at the Tests tab of the Test Cases folder. Because these Tests are at the folder level, they will execute for each request in that folder. When all requests are done for the iteration, call postman.setNextRequest(null) to stop the Collection Runner.

Use test-case-data.csv as the data file for the collection runner. Here’s a copy of the test data:

Test Case User ID Name DOB
1 b4db01 Srinivasa Ramanujan 1887-12-22
2 f00b423 Isaac Newton 1643-01-04
3 ea80d39 Alan Turing 1912-06-23

When you execute a Collection Run, pay attention to the order in which tests are executing. Enjoy!

There is a way to do this:
Add another column in your CSV file say is as your test Flag,

TestFlag Name Age Number
Test_1 a 3 12
Test_2 b 4 12313
Test_3 c 5 1231231
Test_4 d 6 131345423

Now Use the Test Flag, and use Java script If else in the pre-request of the folder structure
if({{testFlag}} === " Test_1"){

}

Same can be done for the remaining folders too.
Try this

1 Like