la1
la1

Reputation: 539

Need to add unique value every time when run the POST api request in jmeter

Need to add unique value every time/always when run the POST api request in jmeter. I have API which is POST request, this request added 'roleId' which should be unique every time (should not use the id which was already created). I have tried below options but response says duplicate id. 1. Add http request with POST body> add 'Counter' to this request with min: 25 and max: 50 with increment:1 When run the request it always starts with '25' and it fails from the second run as it says duplicate value because in the first run this id has been inserted in table 2. User defined variables: used __Random function but for this also same issue. 3. CSV data set config: same issue.

Please suggest what would be the best approach to solve the issue.

Upvotes: 0

Views: 2021

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  • __UUID function can generate a GUID structure which is pretty much unique, something like: 9e73f1a6-c1dc-44f7-b73a-508871f98b83
  • __time() function can generate current timestamp in milliseconds from the start of the Unix epoch, something like 1492417676453 (it won't help if you have > 1 request in millisecond)
  • __threadNum() function returns current virtual user number
  • __iterationNum() function (available via JMeter Plugins) returns current loop number (thread group level)
  • __counter() function which generates an incremented value each time it's being called

You can use any combination of the above in order to generate your roleId, if you have doubts let us know the criteria so we could come up with the best solution. In the meantime check out Apache JMeter Functions - An Introduction article series to get the overall idea about using Functions in JMeter tests.

Upvotes: 4

Related Questions