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.
I want Test 1 to pick data from Row 2, Test 2 to pick data from Row 3… so on and so forth
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?
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?
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.
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.
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.
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!