简体   繁体   中英

JMeter: How to send HTTP requests with different request body for each thread count?

I am testing a REST API that creates a user. This API uses POST method and requires a json payload. I am using the HTTP Request Sampler for my requests which accepts a file for the request payload. The issue I'm having is that the request returns a 409 Conflict for all the hits except for the first thread because after the first thread is executed, the user already exists. Is there a way I can tell JMeter to pick a different payload before each request? How can I organize my request payload for this purpose?

In your payload file you can concatenate your username with jMeter function that makes it unique:

"username": "user ${__time()}"

instead of time function you can either use __UUID or even a __counter function. You can also combine the functions together. Have a look here:

https://www.blazemeter.com/blog/apache-jmeter-functions-introduction

You will have to parametrized your test plan and use CSV data set config to use the data from csv file. I have created a beginners screen cast to explain how to use csv data set config .

As you mentioned you cannot reuse the same data, you will have to either create a big enough csv to match or your concurrent user needs, or use once only controller to not replay those request again, which will create duplicate users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM