JMeter sets a variable to a random option

I use JMeter and I know the functions __Randomand __RandomString. I need to select a random option and store it in a variable, because it will be used as part of the parameter path for several calls. For instance:

http://www.example.com/pets/{random option such as: cat, dog, parakeet}/

I tried doing things like this, where I set the variable ${query}to one, twoor threeusing a random controller with user-defined variables as children. It seems like it should work, but I always get ${query}on three.

Any insights or ideas will be well received. Thanks to everyone in advance.

+3
source share
4 answers

Pre-Process Beanshell

    String[] query = new String[]{"cat", "dog", "parakeet"};
    Random random = new Random();
    int i = random.nextInt(query.length);
    vars.put("randomOption",query[i]);

HTTP-

http://www.example.com/pets/${randomOption}

String[] query = new String[]{"cat", "dog", "parakeet"}; Parameters Beanshell.

    Random random = new Random();
    int i = random.nextInt(query.length);
    vars.put("randomOption",bsh.args[i]);
+8

, Jmeter . , . http://jmeter-plugins.org/wiki/Functions/ , . -:

${__chooseRandom(red,green,blue,orange,violet,magenta,randomColor)}
+2

. :

PreProcessor.

0

, , :

__RandomFromMultipleVars(animalCat|animalDog|animalParakeet, query)

- :

animalCat=cat
animalDog=dog
animalParakeet=parakeet
0

All Articles