'JMeter Random Variable Element not recognise variable from previous step

tl;dr When I use my variable created in Regular Expression Extractor I cannot use it in Random Variable as Maximum Value

Long description:

  • My test structure:
    • enter image description here
  • I have variable my_test what is crated in Regular Expression Extractor
    • request: GET //echo.getpostman.com/get?test=123
    • regex:
    • enter image description here
  • Then I want it use as Maximum Value in Regular Expression Extractor
    • enter image description here
  • So finally I can make request:
    • //echo.getpostman.com/get?test=${rand}

Unfortunately I get error from Random Variable
2016/10/07 07:52:41 ERROR - jmeter.config.RandomVariableConfig: maximum(${my_test}) must be > minimum1)

Why my_test is not evaluated?

I have tried ${__javaScript(parseInt('${my_test}'))} but it looks like it is evaluated before my variable initialization 2016/10/07 08:06:01 ERROR - jmeter.config.RandomVariableConfig: maximum(NaN) must be > minimum1)
If I initialize this variable in Test Plan in User Defined Variables value from that setting will be used - not updated by regex.

I know that I can do //echo.getpostman.com/get?test=${__Random(0,${my_test})}
I'm just curious how pass my variable as value for Maximum Value in Regular Expression Extractor.



Solution 1:[1]

It seems that Random Variable element does not evaluate variables, maybe it worth creating an issue in JMeter Issue Tracker

As a workaround you can substitute it with __Random() function directly where required like:

  • ${__Random(1,${my_test},)} - if you need the value right away, directly in you URL:

    //echo.getpostman.com/get?test=${__Random(1,${my_test},)}
    
  • ${__Random(1,${my_test},rand)} - if if you need to store the value into ${rand} variable as well

See:

Solution 2:[2]

I think it's valid for me to comment on a problem I had, I set the random variable and it didn't work at all, I did everything I could to try to solve it. In the end my problem was a space at the beginning of the variable.

Solution 3:[3]

One possibility is you can use a Beanshell Postprocessor to write the RegEx value to the variable name. After that you can use it as ${variable_name}

NB: Beanshell function vars.get can be used for getting regex value and vars.put can be used for putting it into your variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitri T
Solution 2 Amanda Mata
Solution 3 Aajan