Search code examples
jsonpostmanpostman-collection-runnerpostman-pre-request-script

Create multiple records using JSON in Postman


I want to create 100 driver entries in my DB, for which I am using postman and automating the creation using JSON and json expects a unique driver_number every-time a POST request goes. I can do that same using JMeter but wanted to explore postman.

Attaching the screenshots for reference:

Pre-request Script:

enter image description here

Tests:

enter image description here

Initially tried to create small number of drivers. Once I go for Run Collection option and after running it, it creates just a single driver where loop needs for run for multiple times. And multiple drivers needs to be created.

Here is the screenshot for Run collection:

enter image description here

Can anyone suggest me regarding where am I doing wrong.

Thanks for the suggestion.

  1. No data file is required here.
  2. tried with iteration count, resource is getting created for the first time but for later the counter variable didn't increase and it leads to same driverNumber and at the backend due to validation, resource is not getting created.

enter image description here


Solution

  • There is probably two things to check.

    1. If any CSV file is being used for the request body that it is properly populated in the postman collection runner view.
    2. The 'Iterations' attribute is populated with desired loop count.

    Collection Runner

    Collection Runner Preview Data


    If the CSV file is syntactically valid the iteration will automatically be picked by postman.

    --UPDATED--
    Seems the 'counter' environment variable is not being re-mapped once it is incremented. Try adding pm.environment.set("counter",counter) after the counter++ statement, this should update the environment variable once the increment is done.