Loop Controller in Jmeter

The Loop Controller is one of the Logic controllers in JMeter, allowing a particular section of the Test Plan to be executed repeatedly in a single iteration. This post will discuss the Loop controller in detail.

A loop controller is useful when a user needs to repeat certain steps. It allows the execution of child elements multiple times, such as samplers and other controllers.

We will follow the below steps to use the Loop controller in our Test Plan

Let’s look at above steps one by one.

Set up a Test Plan
  • Launch JMeter.
  • Go to the “File” Menu and select “New”.
  • This will create a new test plan to be used in our example.
Create a test plan in jmeter
Create a Thread Group
  • Right-click on the Test Plan.
  • To create a Thread group, simply go to “Add > Threads (Users) > Thread Groups”.
Create a Thread group in jmeter

The Thread Group is used to execute a specific number of tests. For simplicity, we will keep it set at 1. Please refer to the image below for configurations.

Threads set to 1
Add the Loop Controller
  • Right-click on the Thread Group.
  • And then go to “Add” > “Logic Controller” > “Loop Controller”
Add Logic Controller
Loop Controller Configurations
Loop Controller configurations

As we specified the loop count as 4, the section within the Loop controller will be executed 4 times.

Add an HTTP Sampler inside the Loop Controller

Inside the Loop Controller, we will add an HTTP sampler to execute an HTTP request multiple times.

  • Right-click on the Loop Controller.
  • and then go to “Add” > “Sampler” > “HTTP Request”.
Adding HTTP sampler within Loop Controller

We will hit the GET request on the “https://jsonplaceholder.typicode.com/posts/1” API. So, we will add it to the HTTP sampler by following the below steps.

  • Please enter “https” in the input box that is labelled “Protocol[https]:“.
  • Enter “jsonplaceholder.typicode.com” in the input box labelled “Server Name or IP”.
  • By default, the HTTP request value is set to GET. Since we are only executing a GET request, we won’t be changing it.
  • Set the Path to “/posts/1“.
HTTP Sampler
Add Summary Report

Add the Summary Report by right-clicking on “Loop Controller” and then going to “Add” > “Listener” > “Summary Report”.

Adding summary Report

A summary report will display the number of times the HTTP request was executed alongside other related metrics.

Executing the Test Plan

It’s important to note that the Thread Group loop count has been set to 1, while the Loop Controller count is set to 4. This means that the HTTP sampler inside the Loop Controller will run 4 times (1*4). If we were to set the Thread Group loop count to 3, then the HTTP sampler inside the Loop Controller would have been executed 12 times (3*4).

Click on the green run button to execute the Test Plan.

Start button in jmeter

After executing the Test Plan, take a look at the Summary Report to observe the number of requests that were executed. You will notice that the HTTP request was executed 4 times, which is equal to the count set for the Loop Controller multiplied by the Thread Group count (4*1).

Summary Report results inside Loop Controller

We hope that you have liked the article. If you have any doubts or concerns, please write to us in the comments or mail us at admin@codekru.com.

Liked the article? Share this on

Leave a Comment

Your email address will not be published. Required fields are marked *