Search code examples
groovyjmeterperformance-testingjsr223jmeter-5.0

Jmeter If controller not executing with Groovy


Following is my test plan. Where If controller should execute when user defined variable "userTaskIds" size is greater than zero which is set in previous request.

enter image description here

enter image description here

If controller not executing even though userTaskIds size is greater than zero. If block should execute when previous request is success and userTaskIds >0.

(${JMeterThread.last_sample_ok}) && (${__groovy(vars.get("userTaskIds").size() > 0 )})

ForEach controller enter image description here Following is the debug sampler output enter image description here


Solution

  • The syntax that works should be:

    ${__groovy(vars.get("JMeterThread.last_sample_ok")=="true" && (vars.getObject("userTaskIds").size() > 0 ),)}

    Note it's even better to use __jexl3 function:

    ${__jexl3(vars.get("JMeterThread.last_sample_ok")=="true" && (vars.getObject("userTaskIds").size() > 0 ),)}