Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter while loop (stop loop using its own index)

Tags:

loops

jmeter

I'm using JMeter 5.0 and i'm trying to loop over a database resultset.

For the sake of simplicity here we'll just use "3" instead of vars.getObject("resultSet").size() which is my resultset's size)

I'm trying to use the WHILE component's own index to make it stop

(Please do not show me how to use the counter component since I could make it work myself given all the help i've found regarding JMeter's WHILE uses a counter , but it is counter-intuitive to me (no pun intended), just like incrementing "i" in any other language :

` 
for(int i = 0;i < 10;)
    {
   // do stuff
    i++;
    }
`

I the syntaxes i found and tried (my while component is named LOOP):

  1. ${__jm__LOOP__idx} < 3 : Returns no error but does not stop

  2. ${__javaScript("${__jm__LOOP__idx}" < 3 )} : Returns no error but does not loop either.

  3. ${__javaScript(${__jm__LOOP__idx} < 3)} : Works and stops looping after 3 but returns this error :

    javax.script.ScriptException: <eval>:1:1 Expected ; but found { ${__jm__LOOP__idx} < 3 ^ in <eval> at line number 1 at column number 1 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) ~[nashorn.jar:?]

Thank you in advance for any help you may provide, and for your time.

like image 794
DanielJackson93 Avatar asked May 16 '26 23:05

DanielJackson93


1 Answers

Provided your While Controller is named LOOP, use this as condition , it uses __jexl3 function:

${__jexl3(vars.get("__jm__LOOP__idx") == null || vars.get("__jm__LOOP__idx") < 3,)}

like image 61
UBIK LOAD PACK Avatar answered May 19 '26 04:05

UBIK LOAD PACK