Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change content of Post Body in JMeter HTTP Request

Please forgive my ignorance as I'm a jmeter noob. My webservice accepts JSON objects so I was able to write a rudimentary test where I create an HTTP Request with a JSON object in the "Post Body" portion of the http request.

Anyway, what I want to do is have the HTTP Request choose a different JSON object from a csv file or some other input mechanism so that I can randomize the types of queries that are being run during the load test. Is there a way to do this? The closest is probably using variables (section 4.11 in the user manual) but I have a feeling that's not how variables are used.

A second way I've theorized (although I haven't tried yet since I think the method above is easier) is to create a HTTP Request Default obj with a bunch of HTTP Requests with different JSON objects in them and then use a Random Controller to randomly go thru my multiple HTTP Requests on each pass.

If there's a third way, I'm all ears to learn how to use this tool. I'll continue to read and possibly experiment with plan B above. Thanks in advance for any help you can give me.


UPDATE: So I tried the second way and it seems to work. I had 3 different HTTP requests and the number of times each request gets hit varies from run to run. I still invite answers from the community since I'd like to see what the pros do for issues similar to mine.

like image 210
Classified Avatar asked Sep 17 '13 20:09

Classified


People also ask

How to add body for Post request in JMeter?

Just right click on Test Plan and then click on the element by following this path: Threads (Users) -> Thread Group. Your Thread Group should be added now. And you can keep values in Thread Properties as they are.

How to send Post request with JSON body in JMeter?

To perform sending the JSON payload we need a different configuration. First, we need to add HTTP Header Manager into our HTTP Request in order to set Content-Type as application/json. We then put the JSON payload into the Body Data section of our HTTP Request Sampler.


1 Answers

You have partially answered your question yourself, by saying "csv file or". Here are the specifics.

You will have to use CSV data set config in your test plan to read data from CSV. In your post body, use the variables read from CSV.

Here is a screen cast showing how to use csv data set config.

like image 62
Manish Sapariya Avatar answered Oct 26 '22 01:10

Manish Sapariya