JMeter Logic Controllers determine when to process the Samplers. In simple terms, JMeter Logic Controllers control the order of Samplers execution.
In the topic JMeter Elements, we covered a brief overview of JMeter Controllers. In this topic, we will discuss Logic Controllers in more detail.
JMeter supports many type of Logic Controllers, this tutorial describes the most common logic controller. We will go through a practical, hands on exercise after we give an overview of some of the Logic Controllers.
Types of Controllers in JMeter
If your Test Plan has many Samplers and Controllers you may need to manage and organize them. Simple Controller allows you do this. Simple Controller is like a storage device, which contains Samplers and Controllers.
It does not provide any other benefit apart from organizing Samplers and Controllers. In order to organize elements, you just need to create a Simple Controller and add the child elements under your Simple Controller.
Loop controller loops the request a certain number of times based on its Loop Counter. It can also loop forever, if required.
This is an example of Loop Controller
You create one HTTP request and add it as a child element to Loop Controller with Loop Count = 4. JMeter will send 4 HTTP requests to server.
In the above example, if the Thread Group of the HTTP Request sampler had a loop count of 3, then the total number of times the request would be invoked = 4 x 3 = 12
Recording Controller works like Simple Controller. It is a place to store the recordings when using the HTTP(S) Test Script Recorder (which was earlier known as the HTTP Proxy Server). All the samples of the recording are saved in it, when you record a test script.
It does not have any configuration settings.
Runtime Controller allows the user to set how long its child Samplers can run.
For example, if you add an HTTP Request sampler to a Runtime controller and set the runtime to 10 seconds. This request will run for 10 seconds.
The purpose of module controller is to add modularity to JMeter.
For example: If a web app under test contains units of functionality such as Login, Orders, and Checkout. Each those functionalities can be stored in module. Module Controller allow user to select which module to run.
If you have many test plans which are stored in local drive (*.jmx file). You can include them into current Test Plan by using Include Controller.
Include Controller allow users to “merge” many test plans into one.
In below figure, we include the exist test plan in Test Plan.jmx to current Test Plan
Practical Hands On Exercise with Controllers
In this practical exercise, you will learn how to use a Run Time Controller in your performance tests.
The scenario for this test is below:
- Create a HTTP request to google.com
- Setting the time limit for the test to run
- Send the request to Google server
The workflow for the practice exercise is as follows:
Step 1. Add a Thread Group
Start JMeter and add a Thread Group to the default Test Plan as explained in previous topics. Set the properties as follows: Number of threads – 1, Ramp-Up Period – 1 second, Loop Count – 1. In this exercise, we simulate only one user connecting to Google’s server.
Step 2. Add Runtime Controller
Right click Thread Group and choose Add > Logic Controller > Runtime Controller
Set the Runtime Controller’s run time to 3 seconds.
This means that JMeter will send the requests to Google server for 3 seconds. After that time, it will stop sending the requests.
Step 4. Add HTTP Request Sampler
Add a HTTP Request Sampler under the Runtime Controller. Right click on the Runtime Controller, select Add > Sampler > HTTP Request Sampler. Set the Server name to Google.com.
In this example we have named the sampler – Visit Home Page.
Step 5. Add View Result Tree Listener
Add a View Result Tree Listener to Thread Group. Click on Thread Group, choose Add > Listener > View Results Tree.
Step 6. Run the Test Plan
Click the Run button in menu bar, you will see the Test Running in View Result Tree pane. After 3 seconds, the test will stop.
If you change time Runtime to be longer (for example 10 seconds), you will see the test run longer.
You can download the sample JMeter Runtime Controller Test Plan used in this tutorial to practice on your machine. It already has all the setting explained above.
In the next topic you will learn how to use Timers in JMeter.