Asanke
Asanke

Reputation: 601

JMeter how to select randomely from a extracted set of values

I have a requirement to use randome url from a url list I extract from a json response.

Say I extract them in this mannser

imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4

In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely ("imageUrls_1","imageUrls_2",etc)

I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.

JMeter Is it possible to place a varibale inside a varible name?

Basically I need to use one of the extracted urls randomely in my HTTP request.

Upvotes: 0

Views: 157

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

The easiest way is going for __V() and __Random() functions combination like:

${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}

Demo:

enter image description here

More information: Here’s What to Do to Combine Multiple JMeter Variables

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58822

Use __V function

 ${__V(url)}

The V (variable) function returns the result of evaluating a variable name expression.

Upvotes: 0

Related Questions