Logical Controllers in JMeter

Logic Controllers help you to control the flow of the order of processing of samplers in a thread. It can also change the order of requests coming from their child elements.

logic-controllers-in-jmeter

Following are the list of all Logic Controllers in JMeter :

Include Controller:
  • Include Controller is made to use an external test plan. This controller allows the usage of multiple test plans in JMeter.
    include-controller-page-jmeter
Runtime Controller:
  • Runtime Controller controls the execution of its samplers/requests for the given time. For example, if you have specified Runtime(seconds) to 20, JMeter will run your test for 20 seconds only.
    runtime-controller-jmeter
Loop Controller in Jmeter:
  • Loop Controller will run the samplers/requests stored in it for the definite number of times or forever (if forever checkbox is selected).
  • Select Forever checkbox to run tests for infinite times.
  • Enter the loop count number to run tests for a fixed number of times.
  • For Example, Thread Group loop count is set to 2, Loop Controller loop count is set to 2 and 3 requests are present under Loop Controller node, then JMeter will send a total of “30” Http Requests to the web server under test.
    Total Requests (12) = Thread Group loop count (2)  *  Loop Controller loop count (2)  *  Number of Requests inside Loop Container (3)​
Module Controller:
  • The module controller adds modularity to the JMeter Test Plan.
  • Normally we construct a test plan consists of small units of functionality like Login, Add Product, Logout.
  • The functionality can be stored inside Controllers as modules e.g. Simple Controller can be used to store each module inside it.
In order to run modules by only Module controller, don’t forget to disable Simple Controller.
Recording Controller:
  • Recording Controller is a place holder where the proxy servers can save recorded requests. It has no effects on test execution.

The Following example Demonstrates the Recording controller :

  • Open the JMeter and add Thread Group to it.
  • Next, add Recording Controller.
    add-recording-controller-jmeter
  • Add HTTP(s) Test Script Recorder to the Test Plan.
    add-test-script-recorder-jmeter
  • Before recording, Set the Proxy either in the Google Chrome or in the Firefox browser.
  • Set proxy in the firefox browser and then go back to the JMeter and click on the start button to start Recording.
  • Go to the Target Controller and select the Recording Controller as shown below.
    select-recording-controller-jmeter
  • Now save and then click on the start button and then open the Chercher.Tech /Practice in the Firefox browser and then record the actions.
  • The Recording Controller will record all the actions.
Interleave Controller :
  • Interleave Controller will select only one sampler/requests stored in it, to run in each loop of the thread. It will execute the samplers sequentially.
Transaction Controller:
  • Evaluates the overall time taken to complete a test execution.
Once Only Controller:
  • As per this controller, request added to it will run only once irrespective of the number of users/Loop count specified in the Thread group.
  • This comes into use when one wants all other requests to run more than once but a particular request or a set of requests to run only once during the entire test run.

Adding Once Only Controller :

  • Test Plan > Thread Group > Add > Logic Controller > Once Only Controller
  • Set Value in Thread group = 10 (Just to test the controller), Loop count = 2

Then add the request :

  • Once Only Controller > Add > Sampler > HTTP Request.

Add the listener to view the results :

  • Test Plan > Thread Group > Add > Listeners > View Results in a Tree.
  • Once the test has executed successfully, you will see only 1 request in the results which is expected as per the controller used.
Throughput Controller:
  • The Throughput Controller allows the user to control how often it is executed. There are two modes:
    • Percent execution: This causes the controller to stop executing after a certain number of executions have occurred.
    • Total executions : This causes the controller to stop executing after a certain number of executions have occurred.
IF Controller:
  • The If Controller allows the user to control whether the test elements below it (its children) are run or not.
  • By default, the condition is evaluated only once on initial entry, but you have the option to have it evaluated for every runnable element contained in the controller.
  • The best option (default one) is to check Interpret Condition as Variable Expression? then in the condition field, you have 2 options:
  • Option 1 : Use a variable that contains true or false.
  • Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false.
While Controller:
  • The While Controller runs its children until the condition is False.
    JMeter will expose the looping index as a variable named __jm__<Name of your element>__idx. 
    Example: if your While Controller is named WC, then you can access the looping index through ${__jm__WC__idx}. 
    Index starts at 0
  • Possible condition values are:
    • Blank : Exit loop when the last sample in the loop Fails.
    • LAST : exit loop when the last sample in loop fails. If the last sample just before the loop failed, don't enter the loop.
    • Otherwise : Exit (or don't enter) the loop when the condition is equal to the string False.
Switch Controller:
  • The Switch Controller acts like the Interleave Controller in that it runs one of the subordinate elements on each iteration, but rather than run them in sequence, the controller runs the element defined by the switch value.
  • The switch value can also be a string.
  • If the switch value is out of range, it will run the zeroth element, which therefore acts as the default for the numeric case. It also runs the zeroth element if the value is the empty string.
  • If the value is non-numeric (and non-empty), then the Switch Controller looks for the element with the same string (case is significant).
  • If none of the strings match, then the element named default (case not significant) is selected. If there is no default, then no element is selected, and the controller will not run anything.
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 (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.
  • JMeter will expose the looping index as a variable named __jm__<Name of your element>__idx.
  • For example : if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0
  • 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.
  • The ForEach Controller does not run any samples if inputVar_1 is null. This would be the case if the Regular Expression returned no matches.
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions