2

I know the title may be confusing but this is what I need to do:

I have a list of variables I am pulling from Jquery extractor.

 myVar_1 = 343
 myVar_2 = 98763
 myVar_3 = 5622 
etc

I generate a random number between 1 and myVar_matchNr.

Then I want to navigate to a URL that has an ID of one of the randomly selected variables. For instance, this would be the path I would like as an example:

//mydomain.com/api/resource/${myVar_${randomNumber}}

Which would translate to ( in the case my random number was 2):

 //mydomain.com/api/resource/98763

I have the random number, and I have the list of variables from the Jquery extractor, but I have been unsuccessful getting the value out of the combination.

I have tried the above URL directly. I have tried a beanshell script that looked something like:

 String myvarString = "myVar_" + get("myRandNumber");
 String myVar = get(myvarString);
 set("mySelectedVar", myVar);

That seemed to always come up an empty string.

Any suggestions on how to accomplish this?

2 Answers 2

2

You can combine 2 variables using __V() function like

${__V(myVar_${randomNumber})}

In regards to Beanshell, you need to use vars object which stands for JMeterVariables class instance to manipulate the JMeter Variables like

String myvarString = "myVar_" + vars.get("myRandNumber");
String myVar = vars.get(myvarString);
vars.put("mySelectedVar", myVar);

See Here’s What to Do to Combine Multiple JMeter Variables article for more information on the topic.

Sign up to request clarification or add additional context in comments.

Comments

0

One more option is Random Controller, you can create 3 different request and place it under Random Controller.i hope this will serve the purpose.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.