1
votes

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.

3

3 Answers

3
votes

Random Variable is a Config Element and it will be executed first before any other components get executed first.

4.9 Execution order

  1. Configuration elements
  2. Pre-Processors
  3. Timers
  4. Sampler
  5. Post-Processors (unless SampleResult is null)
  6. Assertions (unless SampleResult is null)
  7. Listeners (unless SampleResult is null)

If two or more Config elements present in the Test Plan, then they will be executed in the order they appear in the Test Plan.

Check the execution order and Scope here: Refer 4.9 7 4.10 here Execution Order and Scope Rules

So, first Random Variable is evaluated first and then Sampler and then regular expression extractor.

When you used User Defined Variables, which is another Config Element, and probably you put it before Random Variable, so it evaluated the expression as you already defined the value for "my_test". But it won't override the value you captured in Regular Expression Extractor.

To solve your problem (one probable solution):

you can use different thread groups. In first thread group, you capture the value and in second thread group, you use the value.

  1. Run Thread Groups consecutively.
  2. Use BeanShell Assertion to capture the value by setProperty. (in first thread group)
  3. Use value using __property() (in thread group)

https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups

0
votes

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.

0
votes

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: