Seirddriezel
Seirddriezel

Reputation: 605

Jmeter: random selection of 5 variables

Sometimes we run a jmeter test on 1 customer (www.exameple.com/pizzadelivery), to stress the customers database. Sometimes we run the test on several customers, to stress the server. (www.exameple.com/pizzadelivery, www.exameple.com/bikeshop, www.exameple.com/bookshop)

I use a "http request defaults" element under my "thread" element to prepare the server / path. I want to do this with variables, so that each thread takes some random path. In a way I only have to change a central variable:

NumberOfCustomers = 1 OR NumberOfCustomers = 3 OR ...

I have:

Customer1 = "pizzadelivery", 
Customer2 = "bikeshop", 
Customer3 = "bookshop", 
...

I tried the next thing in path, but it gives an error path = ${Customer${__Random(1,${NumberOfCustomers})}}

Must be something with ${__V(Customer${__Random(1,${__V(${NumberOfCustomers})})})}

But still this gives errors.

Anyone who can help me? Thanks!

Upvotes: 1

Views: 480

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

It needs to be

${__V(Customer${__Random(1,${NumberOfCustomers},)})}

As per __V() function documentation:

For example, if one has variables A1,A2 and N=1:

${A1} - works OK

${A${N}} - does not work (nested variable reference)

${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1

Also for __Random() function make sure you use NumberOfCustomers + 1 otherwise you will never see the last customer.

Demo:

Functions Demo

See How to Use JMeter Functions posts series for comprehensive information on above and other functions.

Upvotes: 3

Seirddriezel
Seirddriezel

Reputation: 605

  • Under the Thread element, put a Random variable Random Variable

  • Use the new variable with the _v function in the http defaults ${__V(${ChosenCustomer})}

Remark: I first had a javascript function in my http defaults element, but every page request within the same thread had an other path than. With the random variable per thread option, this is not longer an issue.

Upvotes: 0

Related Questions