How to configure an If Controller in JMeter

Conditional branches keep a JMeter test plan from sending every sampler on every run. An If Controller gates the child samplers below it, which is useful when one path should run only for a selected environment, a prior response value, or a specific user-flow branch.

The controller can read a variable that already resolves to true or false, or a function expression such as __groovy that returns true or false. Keeping Interpret Condition as Variable Expression? selected lets JMeter evaluate the function result directly and avoids the slower JavaScript evaluation path used when that option is cleared.

Place the controller at the narrowest tree scope that owns the optional branch. Leave Evaluate for all children cleared when the condition should be checked once as the branch is entered, and select it only when a child sampler or processor can change the value before the next child element runs.

Steps to configure a JMeter If Controller:

  1. Open the test plan in the JMeter GUI.
  2. Select the thread group or controller that should contain the conditional branch.
  3. Add the controller from AddLogic ControllerIf Controller.
  4. Name the controller for the branch it controls.
    Run optional checkout branch
  5. Set the condition in variable-expression mode.
    Name: Run optional checkout branch
    Condition: ${__groovy((props.get('checkout.enabled') ?: 'false') == 'true')}
    Interpret Condition as Variable Expression?: selected
    Evaluate for all children: cleared

    JMeter compares the final condition value with true when variable-expression mode is selected. If the branch depends on an extracted variable instead of a property, use a Groovy expression such as ${__groovy(vars.get('checkout_token') != null)} after the extractor has run.

  6. Move only the optional branch samplers under the If Controller.

    Keep login, token extraction, setup, and control samplers outside this controller when later steps need those values even if the optional branch is skipped.

  7. Save the validation copy of the test plan.
    if-controller-configure.jmx
  8. Run a one-user smoke test with the branch enabled.
    $ jmeter -n -t if-controller-configure.jmx -Jcheckout.enabled=true -l if-true.jtl -j jmeter-true.log
    Creating summariser <summary>
    Created the tree successfully using if-controller-configure.jmx
    Starting standalone test @ 2026 Jun 30 00:27:39 GMT
    Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
    summary =      1 in 00:00:00 =    3.0/s Avg:    25 Min:    25 Max:    25 Err:     0 (0.00%)
    Tidying up ...
    ... end of run

    -Jcheckout.enabled=true supplies the property read by the If Controller expression. Replace that property name with the variable, property, or function input used by the real branch.
    Related: How to override JMeter properties from the command line

  9. Check that the true-case result file contains the child sampler.
    $ cat if-true.jtl
    timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
    1782779260115,25,Optional checkout branch,200,OK,Checkout branch user 1-1,text,true,,28,0,1,1,null,0,0,0
  10. Run the same smoke test with the branch disabled.
    $ jmeter -n -t if-controller-configure.jmx -Jcheckout.enabled=false -l if-false.jtl -j jmeter-false.log
    Creating summariser <summary>
    Created the tree successfully using if-controller-configure.jmx
    Starting standalone test @ 2026 Jun 30 00:27:42 GMT
    Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
    summary =      0 in 00:00:00 = ******/s Avg:     0 Min: 9223372036854775807 Max: -9223372036854775808 Err:     0 (0.00%)
    Tidying up ...
    ... end of run

    A zero-sample run is expected only for this isolated validation plan. In a full test plan, other samplers outside the If Controller can still appear in the result file.

  11. Check that the false-case result file has no child sampler row.
    $ cat if-false.jtl
    timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect