0

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

1 Answers1

1

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.

Vaibhav
  • 116
  • 1
  • 7
  • Thanks Vaibhav for the suggestion. I tried with iteration = 10, so the first request went successful whereas rest of them are getting the same counter value and due to the validation at the backend, the resources are not creating. I will paste the screenshot above with the question. – anaz_Zean07 Jan 30 '22 at 16:09
  • @anaz_Zean07 Right, The counter value will remain same since its not being re-mapped to the same environment variable once it is incremented. Looks like the incremented counter value is mapped to 'driverNumber' a global variable. Try adding `pm.environment.set("counter",counter)` in the pre-request script and re-running the collection runner. – Vaibhav Jan 30 '22 at 16:44
  • Yes, It wasn't mapped with Environment variable properly and after fixing it, it started working. Thanks Vaibhav. – anaz_Zean07 Feb 02 '22 at 05:31