How to change content of Post Body in JMeter HTTP Request

19,170

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.

Share:
19,170

Related videos on Youtube

Classified
Author by

Classified

Updated on September 15, 2022

Comments

  • Classified
    Classified over 1 year

    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.

  • Classified
    Classified over 10 years
    Thx for the link. I'm still not sure how to use CSV from your video. I'm using JMeter 2.9. In my CSV file, each line is a JSON obj. I didn't have separate values on a line like you did in your video. I copied your video and had a var name for the value from the CSV file. I then put ${var} in HTTP Request "Post Body". However, when I run my test, it claims there's an error. When I paste the whole JSON obj into the "Post Body", it succeeds. Is CSV Data Set config only used for "Parameters" or can I also use it for "Post Body" too? I can paste more info into the question if it helps.
  • Manish Sapariya
    Manish Sapariya over 10 years
    The tutorial is not the exact answer for your problem. Instead of using the hardcoded JSON in Post Body, use variables defined in CSV Data set config.