Skip rows from csv data file from test run

Skip few rows from test run based on column value.

I am using a csv file as data file for collection runner . I have around 100+ rows in the file . And there is a column named “include” which accepts true or false . If the include column has false , then I want to skip the row from running in collection runner.

I have tried postman.setNextRequest(null) in pre-request script . But that does not work to skip a row in csv file .

I feel this should be used when we have many collections to run sequentially .

Please do suggest some answer.

The only option I can think of here is to have your test data as a single cell in your CSV.

Store it as a JSON array with quotes (stringified).

You can then use a pre-request script to retrieve the data and store it as a collection variable.

Remember to stringify when storing JSON, and JSON.parse when retrieving.

Still in the pre-request scripts. You will then retrieve the collection variable.

You will the use a JavaScript function called array.shift() which can read the JSON array, retrieve the first element into a new variable, and then delete it from the array.

You can then use new variable for the current request, and you would re-save the current array over the top of the current collection variable (which will now have one less record).

It’s here you can add some extra conditions to check if your “include” element = false. If it does, you just use the array.shift() method again until you get an entry that isn’t false.

In the tests tab, after the request has run. You can retrieve the array again (remember to JSON.parse). Do a length comparison, and then keep running the same request using setNextRequest() until the length == 0. This is how you control the loop.

The following article has an example of this method.

Simulating 100 users using Pre-Request and Tests - :person_raising_hand: Help - Postman Community

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