How can I validate Postman API response contains the String mentioned CSV file

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

When running a Postman requests through Collection runner by passing the values contain in a CSV file for the input parameters, how can I validate each response contain the String text mentioned in the expected value column in this CSV file. I also want to write each response to the Actual result column in this CSV file.

For example after executing the 1st request in the above pic using the Postman collection runner I want to validate the response contains ‘Sydney’ as a text value and give the result as ‘PASS’ or ‘FAIL’ as well as write the actual response to the Actual result column of the above file. This should continue till the last row of the CSV file

Hey @p.s.m.rodrigo! Welcome to the community! :rocket:

You can use the pm API to compare the response and the data from the file. You’ll need to use pm.iterationData.get("value") to get the value from the CSV file and pm.response.json() to get the response from the server.

You can then use a test to get a pass/fail status on it, e.g.:

 pm.test("Response value matches expected value", function () {
         // this is the element you get from the response
         var jsonData = pm.response.json().valueToCheck;
         // this is the element coming from the data file
         pm.expect(jsonData.value).to.eql(pm.iterationData.get("value"));
 });

Updating the CSV file with the response won’t be feasible directly though, you’ll need to find a way to write to a file, here are a few examples of how this could be achieved: