1
votes

I have a while controller that repeats the same request until a condition is met. Inside this controller, I want to select a specific HTTP request depending on a JSON response given by a GET request outside the while loop.

Hence my logic is to set up a while controller (currently working)

${__javaScript(parseInt(${counterApis})<=parseInt(vars.get("FirstNames_matchNr")),)}

which inside has a JSR223 PreProcessor with the following:

vars.put("TypeCode",vars.get("TypeCodes_"+vars.get("counterApis")));

The Idea is simple, the while loop uses the preprocessor to check the value of the variable TypeCode (which can be ADT, CHD or INF depending on the JSON response) and then use this variable to select between a specific POST request depending on this variable.

The Problem: For some reason when I try to add an IF CONTROLLER or a SWITCH CONTROLLER inside the while controller, script crashes an does not access any of the POST requests.

This is how it looks like: If controller Switch Controller

2

2 Answers

0
votes

If you want to execute a specific block of code inside while loop

You can do this by using If controller inside while loop..

To your while loop add a if controller ..

For typecode ADT you can use

${__javaScript(vars.get("TypeCode")=="ADT")}

The condition has to be evaluated to true or false so if you use ${TypeCode}=="ADT" it dosen't work

For more information on while loop follow this link

Please let me know if it helps..

0
votes

You're using wrong JSR223 Test Element. JSR223 PreProcessors are being executed before samplers so your Switch Controller simply does't receive necessary input.

Change JSR223 PreProcessor to JSR223 Sampler and I believe your script will start working as expected. If you don't want to see the JSR223 Sampler in Test Results you can put the following line somewhere:

SampleResult.setIgnore()

Also consider switching to __groovy() function in your While Controller as it is recommended to use the most performing scripting option

javaScript is not the best scripting language for performances in JMeter. If your plan requires a high number of threads it is advised to use __jexl3 or __groovy functions.