Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable input for JMeter Load testing?

I need to load test a service I've developed but I need the data that I post to the web service to have some variance.

I've set up Thread with an Http Request and I've the parameter I need to set but I can't see how I'd go about changing the contents of the HTTP parameter from request to request.

Ideally I'd like to feed in a list of data Items and have JMeter iterate through them.

like image 271
Omar Kooheji Avatar asked Feb 21 '12 14:02

Omar Kooheji


People also ask

What are variables in JMeter?

Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function. When using \ before a variable for a windows path for example C:\test\${test}, ensure you escape the \ otherwise JMeter will not interpret the variable, example: C:\\test\\${test}.


2 Answers

Prepare kind of csv-file with list of your test-params and use it to parametrize your test-samplers, using at least the following:

  1. CSV Data Set Config
    Explained example here, simple example here.

  2. Jmeter functions: __CSVRead, __StringFromFile.

  3. Variables From CSV sampler from jmeter-plugins.

like image 158
Aliaksandr Belik Avatar answered Sep 22 '22 13:09

Aliaksandr Belik


One way would be to prepare a CSV file with all the values that you will need. There are a multitude of different ways to use it afterwards. Alies Belik's answer listed most of them. The drawback of the CSV approach, however, is that you need to generate the list of values, and in some tests you can't simply reuse it without cleaning up/reinitializing the back-end database.

Another option are the functions for generating random values, usually paired with "User Defined Variables" controller.

  • __Random for generating numbers in a given range.
  • __RandomString for generating random strings of a given length and containing a set of characters.

This is a powerful mechanism, but I find it somewhat cumbersome and clunky.

For simple variables, like generating username/password/e-mail combinations, I prefer and find it easier to use the Random Variable config element. It's available since Jmeter 2.3.3. You add it to your thread group and specify a variable to store the random value for each thread. You can later reference this variable in your HTTP sampler, in the GET/POST parameters of the request, by specifying the Value of the parameter to be testuser-${rnd} for username, testpass-${rnd} for password. Each thread will get a different value of ${rnd} so there is a small chance (but there is still a chance) that you will get duplicate values (users).

like image 34
zorlem Avatar answered Sep 23 '22 13:09

zorlem