Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. A Logic Controller can changes the order of requests that come from its child elements. The child elements of a Logic Controller may comprise Samplers, Configuration Elements, and more Logic Controllers. For these requests, JMeter may randomly select (using Random Controller), repeat (using Loop Controller), interchange (using Interleave Controller) etc.
Logic Controllers determine the order in which Samplers are processed
Logic Controller which are available in JMeter are:
- Simple Controller
- Loop Controller
- Once Only Controller
- Interleave Controller
- Random Controller
- Random Order Controller
- Throughput Controller
- Runtime Controller
- If Controller
- While Controller
- Switch Controller
- ForEach Controller
- Module Controller
- Include Controller
- Transaction Controller
- Recording Controller
Let us look into JMeter Logic Controller -> Loop Controller example:
Step 1: Right Click Test Plan>Add>Threads(Users) > Thread Group and Set Loop count as 2
Step 2: Right click on the Thread Group and select Add > Logic Controller > Loop Controller and Set Loop Count as 10.
Loop Count - The number of times the sub-elements of this controller will be iterated each time through a test run.
Step 3: Loop Controller > Add > Sampler > HTTP Request
You can see below that we added HTTP Request to a Loop Controller and Set Server Name as "google.com" and Path as" / "
If we add a HTTP request under the Loop Controller, then the specific sample will loop to the server for the specified number of times.
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 * 10 = 20 HTTP Requests.
Step 4: Thread Group > Add > Listener > Graph Results
Step 5: Save the test plan and Run
We can see the actual no of server on top right which is 2 and number of times those users were used to access the server i.e. 10*2=20. It means all sub requests under loop controller will be executed 20 time.
You can configure Thread Group for a single thread and with a loop count value of one. Instead of letting the Thread Group control the looping, we can use a Loop Controller. Now the above example will be 10*1=10. i.e.. all sub requests under loop controller will be executed 10 times.
Loop Controller embedded in the Thread Group is slightly different here, With Loop count, it will loop all the requests in the thread group where as using the loop controller you can loop specific requests inside the thread group.
- ‹ Selenium 3 - Launch Edge browser using Microsoft Edge Driver
- JMeter Timers - Constant timer Example ›