-
Notifications
You must be signed in to change notification settings - Fork 4
/
creating-templates.html
366 lines (289 loc) · 14.1 KB
/
creating-templates.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- start the processing -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Apache JMeter - User guide: Customizables templates</title>
<style>
.code { font-weight: bold; }
</style>
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76">
<table border="0" cellspacing="0">
<tr>
<td align="left">
<a href="http://www.apache.org"><img style="margin: 0px 30px 0px 0px" title="Apache Software Foundation" width="261" height="106" src="./images/asf-logo.png" border="0"/></a>
</td>
<td align="right">
<a href="http://jmeter.apache.org/"><img width="259" height="88" src="./images/jmeter.png" alt="Apache JMeter" title="Apache JMeter" border="0"/></a>
</td>
</tr>
</table>
<table border="0" cellspacing="4">
<tr><td>
<hr noshade size="1"/>
</td></tr>
<tr>
<td align="left" valign="top">
<br>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica,sanserif">
<strong>Customizable template</strong></font>
</td></tr>
<tr><td>
<blockquote>
<p>
This document describes how to create a customizable template.
</p><table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="folder_structure"><strong>1 Folder structure</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
The template feature uses the bin/templates folder which contains :<br>
<ul>
<li>templates.xml, the file where you declare the templates you want to be able to use</li>
<li>some .jmx and .jmx.fmkr files which are the templates</li>
</ul>
</p><p>Here is how it looks like:
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/template_folder.png"/><br>
<font size="-1">Figure 1 - template folder</font></td></tr></table>
</p></blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="template_creation"><strong>2 Template declaration</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="basic_template_declaration"><strong>2.1 Basic template declaration</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
First of all you must declare your template. To do that, look into the templates.xml file.<br>
This file respect a DTD <br>
Below is the already existing Recording template declaration inside the templates.xml :
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/templates_xml.png"/><br>
<font size="-1">Figure 2 - recording template declaration</font></td></tr></table>
A template declaration is made as follow :<br>
<ul>
<li><tt class="code">template</tt> element which contains the informations described in the followings tags</li>
<li><tt class="code">name</tt> element which contains the template name the user will see</li>
<li><tt class="code">fileName</tt> element which contains the relative path of the template.</li>
<li><tt class="code">description</tt> element which uses html to describe the template</li>
<li><tt class="code">optional</tt> parameters tag (will be discussed later)</li>
</ul>
</p></blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="customizable_template_declaration"><strong>2.2 Customizable template declaration</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
Let's say we want the exact same Recording template as in the 2.1 section, but we want to choose the name
of the xml file where the recording of view result tree will be saved.<br>
<br>
To do so we will use the parameters tag to tell JMeter to ask the user about a name for the concerned file :
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/templates_xml_parameters.png"/><br>
<font size="-1">Figure 3 - recording template with parameters</font></td></tr></table>
<p>
<table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
<tr><td>You can put as many parameter tags as you want in the parameters tag.</td></tr>
</table>
</p>
Let's see what changed here.<br>
Firstly, customs templates are <tt class="code">.jmx.fmkr</tt> files and not only <tt class="code">.jmx</tt>.<br>
<br>
Lastly, we added a <tt class="code">parameters</tt> tag.<br>
As you can see in the image, a <tt class="code">parameters</tt> tag contains <tt class="code">parameter</tt> tags.<br>
Parameter tags are empty and contains 2 attributes :
<ul>
<li><tt class="code">key</tt> is the name of the parameter you will ask the user to fill.</li>
<li><tt class="code">defaultValue</tt> is as its name says, the default value the user will see for the parameter.</li>
</ul>
</p></blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
</blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="template_file"><strong>3 Template file</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="basic_template_file"><strong>3.1 Basic template file</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
The template file is the one you used in the fileName tag when you declared your template.
A template file is just the saving of a JMeter test plan.
</p></blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td bgcolor="#828DA6">
<font color="#ffffff" face="arial,helvetica,sanserif">
<a name="customizable_template_file"><strong>3.2 Customizable template file</strong></a>
</font>
</td></tr>
<tr><td>
<blockquote>
<p>
In the 2.2 section we saw that a custom template file is a .jmx.fmkr file.<br>
The single difference between them is the .jmx.fmkr will be analyzed by JMeter to<br>
detect customs tag. If a custom tag is found, JMeter will try to replace it by the corresponding
given value from the user.<br>
<br>
A custom tag is defined as follow :
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre>[=<key>]</pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
This is based on <a href="https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html#dgui_misc_alternativesyntax_interpolation">Freemarker alternative Interpolation syntax</a>.
Let's illustrate how it works with an example.<br>
Consider the following part of the recording.jmx template file : <br>
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/template_recording_filename.png"/><br>
<font size="-1">Figure 4 - recording.jmx save file</font></td></tr></table>
The surrounded area correspond to the name of the xml file where the View Results Tree output will be saved.
As it is, when you use the template you will always have the same saving filename : <tt class="code">recording.xml</tt>.<br>
<br>
To make it customizable, change your recording template declaration in the templates.xml files by the<br>
one shown in the 2.2 section. Then, rename the recording.jmx file to recording.jmx.fmkr.<br>
<br>
When it's done, Change the above selected line by this one :
<div align="left">
<table cellspacing="4" cellpadding="0" border="0">
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#ffffff"><pre><stringProp name="filename">[=xmlFileName]</stringProp></pre></td>
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
<tr>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
</tr>
</table>
</div>
<br>
It's over ! With this configuration, if you chose to use the recording template, JMeter will ask you
a xmlFileName (correspond to the key value in the declaration).
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/template_parameters_window.png"/><br>
<font size="-1">Figure 5 - JMeter asks you the value you want to put for the key</font></td></tr></table>
Then, you will find the expected value in the created template where you placed the [=xmlFileName] tag :
<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="./images/screenshots/templates/template_recording_retrieved_value.png"/><br>
<font size="-1">Figure 6 - the value changed</font></td></tr></table>
</p></blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
</blockquote>
</td></tr>
<tr><td><br></td></tr>
</table>
</blockquote>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<br>
</td>
</tr>
<tr><td>
<hr noshade size="1"/>
</td></tr>
<tr>
<td>
<table width=100%>
<tr>
<td>
<font color="#525D76" size="-1"><em>
Copyright © 1999-2019, Apache Software Foundation
</em></font>
</td>
<td align="right">
<font color="#525D76" size="-1"><em>
$Id$
</em></font>
</td>
</tr>
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1">
Apache, Apache JMeter, JMeter, the Apache feather, and the Apache JMeter logo are
trademarks of the Apache Software Foundation.
</font>
</div>
</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<!-- end the processing -->