Search code examples
arraysjmeterbeanshell

How to send a variable length list or array of parameters with a HTTP POST request in JMeter?


I'm making JMeter load tests for an ASP.NET web application, and the tests should post some data to the server. Specifically, they should post grades for all the pupils in a class. However, the tests are supposed to be general, so that they can be run towards different schools with a small change in the configuration.

However, this creates a problem when the grades are posted, since the number of parameters in the post request (pupils in the class) can vary from run to run, or even from thread to thread. Currently I only know how to pass parameters through the HTTP request form as shown below: enter image description here

However, in the next thread there could be a saveModel.PupilOrderAndBehaviours[2] or even up to 30. I have all of this information available directly from csv files. That is, I can tell JMeter ahead of time how many pupils will be in each class, and what grades each of them should receive, so I do not need to read this out from previous responses or anything like that.

Is there a way, potentially using BeanShell, I can configure JMeter to do this correctly?


Solution

  • It can be done with Beanshell Preprocessor.

    int count = 10;
    for(int i=1;i<=count;i++) 
    {
         sampler.addArgument("Parameter" + i, "Value" + i);
    }
    

    It adds 10 parameters as given below @ run time.

    enter image description here

    Please refer to this site.

    http://theworkaholic.blogspot.com/2010/03/dynamic-parameters-in-jmeter.html