0

I have written a REST API and now my requirement is to load test it for 1k calls or something. Problem is the request json has an unique attribute - Cnumber which needs to be changed for every request.

json request:

{ "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "C7" }

how can I make this request for 1K users concurrently with Cnumber changes in every request?

cSharp
  • 25
  • 1
  • 8
  • 1
    See https://stackoverflow.com/questions/45328356/generate-random-number-variables-in-jmeter/45328753#45328753 – Ori Marko Sep 21 '21 at 17:00
  • @user7294900 can I also use it in Body Data like {"Cnumber": ${__Random(0000,9999)}}, something like this. request body is a lengthy json. – cSharp Sep 21 '21 at 17:06
  • See (how-to-generate-a-random-unique-mobile-number)[https://stackoverflow.com/questions/69106489/how-to-generate-a-random-unique-mobile-number-in-jmeter] for details to generate a random, unique number. – Janesh Kodikara Sep 22 '21 at 05:02
  • `${__Random(0000,9999)}}, ` shall not be used. It generates a random number but not a unique number. – Janesh Kodikara Sep 22 '21 at 05:03

2 Answers2

3

Depending on what you're trying to achieve:

  1. Incrementing number can be generated using __counter() function like:

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__counter(FALSE,)}" }
    
  2. Random number can be generated using __Random() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__Random(1,2147483647,)}" }
    
  3. Random alphanumeric string can be generated using __RandomString() function like:

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__RandomString(2,abcdefjhijklmnopqrstuvwxyz0123456789,)}" }
    
  4. Current thread number: __threadNum() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__threadNum}" }
    
  5. GUID-like structure: __UUID() function

    { "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "${__UUID}" }
    

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • thank you , this was useful , what about if we also want other fields to be changed with new request like a different Name, Email Id ? have to config it in csv ? – cSharp Sep 30 '21 at 05:17
  • Depending on whether you want to use random data or a pre-defined data set you either could go for the aforementioned [__RandomString() function](https://jmeter.apache.org/usermanual/functions.html#__RandomString) or [CSV Data Set Config](https://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config) or use i.e. [Faker library](https://github.com/DiUS/java-faker) from [__groovy() function](https://www.blazemeter.com/blog/groovy-new-black/) – Dmitri T Sep 30 '21 at 07:35
2

You could use a timestamp...

{ "Code": "WEB", "Pfix": null, "Name": "Ronaldo", "Cnumber": "C${__time}" }

Cnumber with timestamp example image

w4dd325
  • 527
  • 5
  • 21
  • thank you , this was useful , what about if we also want other fields to be changed with new request like a different Name, Email Id ? have to config it in csv ? – cSharp Sep 30 '21 at 05:17
  • Could use RandomString for email, set to say "10" length using any letter of the alphabet... Email example = ${__RandomString(10,abcdefghijklmnopqrstuvwxyz)}@gmail.com Output example = aimcwyoshb@gmail.com – w4dd325 Sep 30 '21 at 06:53