Validate Large Number of Response Data in Postman

     We know that validation of response data from an API is very important at the prior stage of functional and also during the QA execution stage. You may need to validate the response data from API against the AUT or you may need to validate the response data from API against the database result set.

     I had a situation or scenario to validate millions of records in API response against the database table result set. It’s very difficult to achieve millions of record validation, even if we do via manual testing it will take time or getting bore after 50 or 60 record validation. We can achieve this validation by following below procedures:

Prerequisites: Make sure that the Dataset or Resultset available as CSV or JSON file. 

  1. Create Postman request.
  2. Add test case in Postman to iterate and validate the data from CSV or JSON against the response of the API. 
  3. Run the collection using Test Runner, there map the CSV or JSON file.

     I did achieve this via postman scripting and later at the time of execution using collection runner validated the response against the dumps exported from the database. I used below sample script in Postman tests,

pm.test(“Verify ID Present”, function () {
pm.expect(pm.response.text()).to.include(pm.iterationData.get(“column_name_in_the_CSV”));
console.log(“ID “+data[“column_name_in_the_csv”]+” is present”)
});

In the above test, validating the ID values from response data against the ID values that exported from database result set. Like this, we can create multiple tests to validate the response data. pm.iterationData.get(“column_name_in_the_CSV”) this method will iterate through all the data from the respective column of the CSV file and check against the API response.

     Once we create the test scripts in Postman, we can open Run Collection against your collection to get the Runner view (we discussed the execution process in the previous article). In the Runner view, we can upload the CSV file that exported from the database and starts execution. Finally, we will get the results including Passed and Failed cases. If we export the collection as JSON from Postman, we can run the collection with CSV file and generate an HTML report using newman library via command-line. The code as follows:

newman run “collection_JSON_file_path” -d “CSV_file_path” -r htmlextra

     The above command helps to run the same collection, validate the CSV data, and finally, it will generate an HTML report. You can try this way of validation instead of stretching to achieve this kind of testing situation.

make it perfect!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s