In this blog post, we are going to see about how to create custom templates in JMeter. Earlier post explains about JMeter Templates, its purpose and how to add JMeter templates to your Test Plan. The goal of this article is to teach you how to customize the JMeter templates in JMeter.
Suppose you are working on a banking application where you perform following transactions repeatedly:
Table of Contents
Scenario 1:
- Login
- Check Balance
- Logout
Scenario 2:
- Login
- Apply Loan
- Logout
Scenario n:
- Login
- Pay Bill
- Logout
In this case, you might need to create many test plans in same fashion i.e. adding a Thread Group, adding HTTP Cookie Manager, adding HTTP Authorization Manager, adding three Loop Controllers, and two Listeners.
To expedite the process of creating items for your thread group, it is ideal to create a custom template. By one click you will be able to add the thread group with all your desired elements.
Steps to create custom templates in JMeter?
Follow the below steps sequentially to create custom templates:
- Go to JMETER_HOME\bin\templates folder.
- Open templates.xml in your favorite editor. I use Notepad++ or jEdit.
- Copy below code and paste it in the templates.xml just before </template> tag.
<template isTestPlan="true"> Â Â Â Â Â Â Â <name>My Test Plan</name> Â Â Â Â Â Â Â <fileName>/bin/templates/my-test-plan.jmx</fileName> Â Â Â Â Â Â Â <description><![CDATA[ Â Â Â Â Â Â Â <h1>This is my test plan</h1> Â Â Â Â Â Â Â <h2>My reference link</h2> Â Â Â Â Â Â Â Â Â Â Â <ul> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <li><a href="http://myurl" >http://myurl</a></li> Â Â Â Â Â Â Â Â Â Â Â </ul>Â Â Â Â Â Â Â Â Â Â Â Â Â ]]></description>
- You can change the bold text in the above code as per your need.
- Now launch JMeter 2.11 and design your test plan that you need to convert it to a template. Below is the sample test plan that I have created for demonstration purpose.
- Save your created test plan as my-test-plan.jmx in the following JMETER_HOME\>/bin/templates/
- Check whether the name of your JMeter template and its path is same as you mentioned in the templates.xml file.
- Click on Templates icon, and then click on Reload Templates button. You could see your created template gets listed out as shown below.
- Click on Create button to add it your test plan.