Jmeter Include Controller Example

Include controller in jmeter is very useful if you wants to break your test plan in small fragments. There are many different jmeter controllers available. Each of them have different purpose as per it's name. Jmeter include controller is useful to include external test fragment in your test. Means you can include external test fragment in your software load test plan using include controller in jmeter.

Let's take simple example. You have 5 different load test scenario for your software web application and each needs login to software web application to perform next steps. That means you need to record login steps in all 5 scenario's load test plan. So you are duplicating the common process steps in each test plan and it will increase test plan maintenance cost too. Include controller can help you in this situation.

Jmeter include controller provides you facility to use external test fragment in your test plan. So you have to save login steps as a test fragment and then you can use that test fragment in your all software load test plans using include controller in jmeter. Let's understand with practical example.

Include controller in jmeter

I have 4 different requests as bellow.
  1. Login
  2. My Account
  3. My Orders
  4. My Address
This is one scenario of my software web application's load test plan and there are more 4 such scenarios where Login request is required. So I will save Login request as test fragment as shown in bellow given steps and then i will use that test fragment in my different tests to login.
  • Put Login request under Simple Controller.
  • Right click on Simple Controller
Jmeter Include Controller
  • Select "Save as Test Fragment".
Include Controller in Jmeter
  • Give your desired name to test fragment and save it at your desired location. I have saved it with "Login module.jmx" at E:\JMeter\ path.
Now create new software load test plan and 
  • Add Thread Group under Test Plan(Right click on Test Plan -> Add -> Threads -> Thread Group).
  • Add Include Controller under Thread Group(Right click on Thread Group -> Add -> Logic Controller -> Include Controller).
usage of Include Controller in Jmeter
  • In Include controller, Select "Login module.jmx" from E:\JMeter\ as Filename using browse button as shown in bellow image.
Include file in Include Controller

  • Add simple controller under Thread Group and add/record My Account, My Orders and My Address requests under it as shown in bellow image. 
  • Also add View Results Tree listener under Thread Group.


You can download "Login module.jmx" and test plan for Include Controller from THIS PAGE.

Now if you run above test plan using Number of Threads = 1 and Loop count = 1 in Thread Group,
  • First it will execute Test Fragment(Which contains login request) of Include Controller and 
  • Then it will execute requests(My Account, My Orders and My Address requests) of simple controller as shown in bellow given image.

Same way, You can use "Login module.jmx" in all other jmeter software load test plans where login is required.

This way, jmeter include controller allows you to break your test plan to reuse it in other test plans and reduce duplication of common steps. So it will also reduce cost of test plan maintenance.

2 comments: