JakubP
JakubP

Reputation: 13

JMeter - how to randomize number of parameters in request

I am new to JMeter. In my GET request I want to have random number of parameters, so sometimes I want to have:

a = value1
a = value2
a = value3

and sometimes I want to have

a = value1
a = value2

etc.

Can I achieve it in JMeter in another way than making separate request modules?

Upvotes: 1

Views: 1764

Answers (3)

Dmitri T
Dmitri T

Reputation: 168072

You can do it via i.e. Beanshell PreProcessor like:

sampler.addArgument("name", "value");

See:

Upvotes: 0

timbre timbre
timbre timbre

Reputation: 13970

You can specify parameters dynamically in the Path field, using a variable:

dynamic parameters in Path field

The variable should be created / formatted before HTTP request is sent. For example here I am using counter and BeanShell pre-processor to create a proper set of parameters:

Example: dynamic parameters

So if I run this with 3 iterations, I will get:

GET http://stackoverflow.com/x?a=value0
GET http://stackoverflow.com/x?a=value0&a=value1
GET http://stackoverflow.com/x?a=value0&a=value1&a=value2

etc. Of course the logic of creating params should be based on your needs, this is merely an example. The reusable part of that example is saving params in a string, and then saving them into variable:

String myDynamicParameters = "";
// your logic here
vars.put("myDynamicParameters", myDynamicParameters);

Upvotes: 1

Payam
Payam

Reputation: 1209

If you want to generate variable directly inside your GET parameters, the fastest way is to use inline snippets. something like:

GET http://xx.com/${__Random(1,99999)}

Upvotes: 0

Related Questions