JMeter Complete Element Reference – Part IV

In this article, we will discuss about  the next set of elements i.e Logic Controllers, importance  of controllers, types of controllers and their usage  in our test. In case if you have missed the older parts, click here 12, 3.

Logic Controllers

Logic Controllers let you customize the logic that JMeter uses to decide when to send user requests. Logic Controllers basically determine the order in which Samplers are processed. They can modify the requests themselves, cause JMeter to repeat requests, etc.

Types of Controllers

Apache JMeter provides various type of logical controller which lets you define the order of processing request in a Thread Group.

Simple Controller

Simple controller lets you to organize user request  and other Logic Controllers.Simple controller doesn’t have any functionality unlike other controllers. Simple controller is just a container of  samplers(user requests) and other controller under a thread group.


 In this example, we created a Test Plan that has four HTTP requests. We grouped the requests by placing them inside Simple Logic Controllers. Remember, the Simple Logic Controller has no effect on how JMeter processes the controller(s) you add to it. So, in this example, JMeter sends the requests in the following order: Home Page, News Page, Component Reference Page, Functions Page.  So Simple controller can be used to store user requests and other logic controllers.

Loop Controller

Loop Controller makes the user request run specified number of times or run forever. If you add Generative or Logic Controllers to a Loop Controller, JMeter will loop through them a certain number of times, in addition to the loop value you specified for the Thread Group. For example, if you add one HTTP Request to a Loop Controller with a loop count of two, and configure the Thread Group loop count to three, JMeter will send a total of 2 * 3 = 6 HTTP Requests.

Lets examine with an example:

We have created test plan which consists of two logic controllers i.e one simple and loop controller. Each controller consist of a single HTTP Request. Now i have scenarios where “Home Page” requested should be sent to server once and “create Visit Page” should be sent 5 times . How do i achieve this ? the answer is Loop Controller. 


To achieve the above scenarios i will set my loop count to 5,  so that the “Create Visit” Page request will be sent to server 5 times. This can be done as follows:


Now when you run the test scenario with a single user, the “Home Page” request will be fired once and “Create visit Page” will be sent 5 times to the server as we set our loop count to 5. The result will be as follows:


Once Only Controller

The Once Only Logic Controller tells JMeter to process HTTP requests or logic controllers inside it only once per Thread, and skip or pass over any requests under it during further iterations through the test plan.

The Once Only Controller will now execute always during the first iteration of any looping parent controller. Thus, if the Once Only Controller is placed under a Loop Controller specified to loop 5 times, then the Once Only Controller will execute only on the first iteration through the Loop Controller (ie, every 5 times). Note this means the Once Only Controller will still behave as previously expected if put under a Thread Group (runs only once per test per Thread), but now the user has more flexibility in the use of the Once Only Controller.

Lets examine with an example:

we created a Test Plan that has two threads that sends HTTP requests. Each thread sends one request to the Home Page, followed by five requests to the create visit Page. Although we configured the Thread Group to iterate five times, each JMeter thread only sends one request to the Home Page because this request lives inside a Once Only Controller.

1. Set your thread group to 2 Users and number of iterations to send the HTTP Request. You can do it as follows:


2. Now add Once only Controller to the thread group and a place a HTTP Request sampler inside the controller. Your configuration should look like this:


3. Now run your test according to the thread group configurations. As you can observe from the screenshot, Create Visit Page will execute only two times through out the test and Home Page request is executed 10 times as we set our loop count to five. This clearly indicates that Once only controller will execute only once per Thread, and pass over any requests under it during further iterations through the test plan. The test results can be as follows:


Transaction Controller

The Transaction Controller generates an additional sample which measures the overall time taken to perform the nested test elements.

The generated sample time includes all the times for the nested samplers, and any timers etc. Depending on the clock resolution, it may be slightly longer than the sum of the individual samplers plus timers. The clock might tick after the controller recorded the start time but before the first sample starts.The generated sample is only regarded as successful if all its sub-samples are successful.


NOTE:  when the check box “Include duration of timer and pre-post processors in generated sample” is checked, the time includes all processing within the controller scope, not just the samples.

Let’s Examine with an Example:

We have created a Test plan  with two HTTP Request place inside a Transaction controller. When we run the test, Transaction Controller will give you the overall time taken by the HTTP requests. The results can be as follows:


Recording Controller

The Recording Controller is a place holder indicating where the proxy server should record samples to. During test run, it has no effect, similar to the Simple Controller. But during recording using the HTTP(S) Test Script Recorder , all recorded samples will by default be saved under the Recording Controller.


Interleave Controller

If you add Generative or Logic Controllers to an Interleave Controller, JMeter will alternate among each of the other controllers for each loop iteration. If ignore sub-controller blocks is checked, then the interleave controller will treat sub-controllers like single request elements and only allow one request per controller at a time.


Random Controller

The Random Logic Controller acts similarly to the Interleave Controller, except that instead of going in order through its sub-controllers and samplers, it picks one at random at each pass.


IF Controller

 If Controller allows the user to control whether the test elements place under it  (its children) are allowed to run or not.By default the condition is interpreted as JavaScript code that returns “true” or “false”, but this can be overridden.  If Interpret Condition as Variable Expression is selected, then the condition must be an expression that evaluates to “true” (case is ignored). For example, ${FOUND} or ${__jexl(${VAR} > 100)}. Unlike the JavaScript case, the condition is only checked to see if it matches “true” (case is ignored).If there is an error interpreting the code, the condition is assumed to be false, and a message is logged in jmeter.log.

Lets examine with an Example:

We have created a test plan which consists of two IF controllers. Two HTTP Requests samplers are palace inside each of the controller. As we already know If controller evaluates a condition to TRUE, based on the conditions placed in test plan respective request will be fired to the server.  Lets have glance at the configuration:


IF controller configurations can be as follows:


Now, When we run our test based on the conditions defined in the respective requests will be sent to the server. The test results can be as follows:


As you can see, Home Page & create Visit Page are executed as the condition is evaluated to TRUE(refer here). Home Page1 & Create Visit Page1 are not executed because the condition in the IF controller returns FALSE.

While Controller

The While Controller runs its children until the condition is “false”.The condition can be any variable or function that eventually evaluates to the string “false”. This allows the use of JavaScript, BeanShell, properties or variables as needed.

Possible condition values:

  • blank – exit loop when last sample in loop fails
  • LAST – exit loop when last sample in loop fails. If the last sample just before the loop failed, don’t enter loop.
  • Otherwise – exit (or don’t enter) the loop when the condition is equal to the string “false”.

For example:

  • ${VAR} – where VAR is set to false by some other test element
  • ${__javaScript(${C}==10)}
  • ${__javaScript(“${VAR2}”==”abcd”)}
  • ${_P(property)} – where property is set to “false” somewhere else


ForEach Controller

A ForEach controller loops through the values of a set of related variables. When you add samplers (or controllers) to a ForEach controller, every sample sample (or controller) is executed one or more times, where during every loop the variable has a new value. The input should consist of several variables, each extended with an underscore and a number. Each such variable must have a value. So for example when the input variable has the name inputVar, the following variables should have been defined:

  • inputVar_1 = wendy
  • inputVar_2 = charles
  • inputVar_3 = peter
  • inputVar_4 = john

Note: the “_” separator is now optional.

When the return variable is given as “returnVar”, the collection of samplers and controllers under the ForEach controller will be executed 4 consecutive times, with the return variable having the respective above values, which can then be used in the samplers.

It is especially suited for running with the regular expression post-processor. This can “create” the necessary input variables out of the result data of a previous request. By omitting the “_” separator, the ForEach Controller can be used to loop through the groups by using the input variable refName_g, and can also loop through all the groups in all the matches by using an input variable of the form refName_${C}_g, where C is a counter variable.


If you enjoy reading article then you can subscribe our updates for FREE, just add your email id . I will keep on updating the article for latest testing information. Subscribe and stay tuned for updates, there’s lot more to come.

🙂 Happy Performance Testing !! 🙂


3 thoughts on “JMeter Complete Element Reference – Part IV

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s