Skip to content
  • ZipCode Api
  • Blog
  • About RedLine13
RedLine13
RedLine13
Primary Navigation Menu
Menu
  • Start Testing
  • Demo
  • Pricing
  • JMeter
  • Partners
  • Docs
    • Documentation Home
    • AWS Set Up for load testing
    • AWS Approval for Large Tests
    • PHP, NodeJS, Python Load Tests
    • Scalability
    • Jenkins Plugin Setup
    • Premium Features
    • Knowledge Base

Using the JMeter “If” Controller

By: David Koziel

Using the JMeter If Controller

JMeter contains a built-in component that can assist in controlling the logical flow of a load test based on internal conditions. Using the If Controller, conditional logic can be set up to either run once for a group of elements, or optionally for each element within a set. Only if the specified condition is “true” will items within the If Controller be executed.

The If Controller is a JMeter built-in component that can assist with logic flow control of your load tests
The “If Controller” is a JMeter built-in component that can assist with logic flow control of your load tests.

Once added to a test plan, the If Controller acts as a container for one or more child components. These can be sampler elements such as HTTP Requests, or other logical components. Additionally, it is possible to nest If Controllers to create more complicated, branching test logic:

If Controllers can be nested to create branching test logic
“If Controllers” can be nested to create branching test logic.

Evaluating Conditions

Subscribing to classic “if-then” logic, flow control is evaluated as “true” or “false”. This primarily occurs in one of two ways. JMeter variables can hold boolean values and be referenced directly as the condition, using standard ${…} notation. The second method afforded by the If Controller is evaluating a snippet of JavaScript as “true” or “false”.

For performance reasons, it is strongly recommended that Java Expression Language (JEXL) be used by invoking the jexl3() method. This can be accomplished via the JMeter special function, i.e., ${__jexl3()}. You do have the option to use JavaScript by unchecking the “Interpret Condition as Variable Expression” setting. However, while this can be more flexible there is a severe performance penalty as alerted when this setting is unchecked:

Performance can be severely affected when evaluating expressions as JavaScript
Performance can be severely affected when evaluating expressions as JavaScript.

Handling Child Elements

There are two behaviors to select from when evaluating child elements. The default behavior is to evaluate the condition of the If Controller once for the entire set of children. This will result in an all-or-nothing pattern of execution. Optionally, you may tick the “Evaluate for all children” checkbox which will have the effect of running the condition for each child element and only executing on those occurrences where the result is “true”.


Did you know that RedLine13 offers a full-featured, time-limited free trial?  Sign up now, and start testing today!

2024-07-18
Previous Post: Dynamically Parse HTML with k6
Next Post: Running JMeter from the Local Command Line

Recent Posts

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener

Related

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • SAML Configuration with Azure AD and RedLine13
  • SAML Configuration with OKTA and RedLine13
  • SAML Configuration with Google and RedLine13
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener
  • Using Test Fragments in JMeter Tests
  • Step-by-Step Guide to Testing with JMeter

© RedLine13, LLC | Privacy Policy | Contract
Contact Us: info@redline13.com

Designed using Responsive Brix. Powered by WordPress.