Templates or how to speed up your Tests scripting with JMeter
JMeter sometimes looks unfriendly to newbies due to its large scope of features,documentation is rather rich and they wonder sometimes where to start.
Hopefully JMeter 2.10 brings a major improvement in this field through introduction of Templates feature.
This feature is also useful to more advanced users as it saves you lot of time creating Test skeleton.
We will see in this blog:
- how to use this feature,
- how to create your own template and register them.
What are Templates
Templates let you in 2 clicks :
- create New Test Plan (Web Test Plan, Recording, Soap Webservice Test, JDBC Test …)
- merge snippets into your current Test Plan
The template feature was first contributed by our support within BUG 55085. As always JMeter Core team improved it in many fields by adding:
- Merge feature which allow to create not only New Test Plan but also Test Plan snippets
- Hot Reloading of Templates
- Ability to use relative paths
Using Templates feature is as easy as:
- Selecting Menu File > Templates…
- Or clicking on Templates… Icon
Once done a Popup appears showing the first template, you select in the Upper List what you want to do, in the screenshot below the “Recording” Template is shown which creates for you a Test Plan to record Web Navigation.
Snippet templates let you add some existing code to existing Test Plan by selecting the Parent node to which you want to add the snippet.
When the template is a snippet, Merge button will appear instead of Create:
You need to select a correct node before clicking Template menu, if node does not accept snippet, you will get a warning:
As of JMeter 2.10, 9 Test Plan templates are proposed:
- Recording Test Plan
- JDBC Test Plan
- SOAP Webservice Test Plan
- Simple Web Test Plan
- Advanced Web Test Plan
- MongoDB Load Test
- FTP Test Plan
- LDAP Test Plan
- Extended LDAP Test Plan
And one Snippet Test Plan:
- Beanshell Sampler (showing how to code a BeanShell sampler)
Create your own templates
Create the Template
Test Plan template
Creating a Template is as easy as saving a Test Plan in a folder of your choice within JMeter installation folder.
If your template is a snippet, right click on the node you want to save and select “Save selection As…”
You can then use the saved file as a snippet template.
Register the Template
Create Template description
Registration is done within an XML file defined by “templates.dtd” (located in jmeter/bin/templates).
A description is composed of 4 XML nodes:
- <template> : Root tag for one template with an attribute isTestPlan telling wether the JMX file is a snippet to merge or a full test plan
- <name> : Template name which will appear in the List Box we saw earlier
- <fileName> : Path to JMX file which can be a full Test plan or a snippet
- <description>: A inline CDATA block containing HTML text which will be the manual for the template use
A simple example defining a Test Plan publishing to a JMS Topic :
<!DOCTYPE templates SYSTEM "templates.dtd"> <templates> <template isTestPlan="true"> <name>JMS Topic Publishing</name> <fileName>/bin/templates/jmsPublishTemplate.jmx</fileName> <description><![CDATA[ <h1>Template showing how to publish to a JMS Topic in ActiveMQ</h1> <h2>JMeter Configuration</h2> <p> <ul> <li>Add ActiveMQ jars to jmeter/lib folder</li> <li>Adapt User Defined Variables to your configuration</li> </ul> </p> <h2>Useful links</h2> <p> <ul> <li><a href="http://jmeter.apache.org/usermanual/build-jms-topic-test-plan.html" >Building a JMS Topic Test Plan</a></li> <li><a href="http://activemq.apache.org/jndi-support.html" >ActiveMQ Configuration</a></li> </ul> </p> ]]></description> </template> </templates>
Let’s save this file to <JMeter Home>/bin/templates/ulpTemplates.xml
Register description within JMeter
Editer user.properties and add template.files property:
First path “/bin/templates/templates.xml” is the path to CORE jmeter templates.
Philippe Mouawad works as an Architect and technical expert for Ubik-Ingenierie where he leads among other things the development of UbikLoadPack a set of Commercial Plugins for Apache JMeter allowing to load test different protocols like HLS, GWT, Flex.
Philippe is a committer on the Apache JMeter project and member of the PMC since October 2011.
Finally he is a co-author of a french book on JMeter called Maîriser JMeter: Du test de charge à Devops.
- Ubik Load Pack is a JMeter based solution for complex protocols.
- Follow us on Twitter and StackOverflow.
- Follow Apache JMeter on Twitter
Comments are closed.
- UBIK LOAD PACK VIDEO STREAMING PLUGIN 27 November
- UBIK LOAD PACK AUTO-CORRELATOR PLUGIN 26 November
- Release of UbikLoadPack Video Streaming Plugin 6.5.0 22 November