📄 functions.html
字号:
The split function splits the string passed to it according to the delimiter,
and returns the original string. If any delimiters are adjacent, "?" is returned as the value.
The split strings are returned in the variables ${VAR_1}, ${VAR_2} etc.
The count of variables is returned in ${VAR_n}.
From JMeter 2.1.2 onwards, a trailing delimiter is treated as a missing variable, and "?" is returned.
Also, to allow it to work better with the ForEach controller,
__split now deletes the first unused variable in case it was set by a previous split.
</p>
<p>
</p>
Example:
<code>
<br>
</br>
Define VAR="a||c|" in the test plan.
<br>
</br>
${__split(${VAR},VAR),|}
<br>
</br>
This will return the contents of VAR, i.e. "a||c|" and set the following variables:
<br>
</br>
VAR_n=4 (3 in JMeter 2.1.1 and earlier)
<br>
</br>
VAR_1=a
<br>
</br>
VAR_2=?
<br>
</br>
VAR_3=c
<br>
</br>
VAR_4=? (null in JMeter 2.1.1 and earlier)
<br>
</br>
VAR_5=null (in JMeter 2.1.2 and later)
</code>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>String to split</td>
<td>A delimited string, e.g. "a|b|c"
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Name of variable</td>
<td>A reference name for reusing the value
computed by this function.
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Delimiter</td>
<td>The delimiter character, e.g.
<b>
|
</b>
.
If omitted,
<b>
,
</b>
is used. Note that
<b>
,
</b>
would need to be specified as
<b>
\,
</b>
.
</td>
<td>
No
</td>
</tr>
</table>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__XPath">19.5.15 __XPath</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The XPath function reads an XML file and matches the XPath.
Each time the function is called, the next match will be returned.
At end of file, it will wrap around to the start.
<p><table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
<tr><td>Note that the entire file is held in memory, so this function should not be used for very large files.
</td></tr>
</table></p>
</p>
<p>
</p>
Example:
<code>
<br>
</br>
<br>
</br>
${__XPath(/path/to/build.xml, //target/@name)}
<br>
</br>
This will match all targets in build.xml and return the contents of the next name attribute
</code>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>XML file to parse</td>
<td> a XML file to parse
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>XPath</td>
<td> a XPath expression to match nodes in the XML file
</td>
<td>
Yes
</td>
</tr>
</table>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__setProperty">19.5.16 __setProperty</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The setProperty function sets the value of a JMeter property.
The default return value from the function is the empty string,
so the function call can be used anywhere functions are valid.
</p>
<p>
The original value can be returned by setting the optional 3rd parameter to "true".
</p>
<p>
Properties are global to JMeter,
so can be used to communicate between threads and thread groups
</p>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>Property Name</td>
<td>The property name to be set.
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Property Value</td>
<td>The value for the property.
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>True/False</td>
<td>Should the original value be returned?
</td>
<td>
No
</td>
</tr>
</table>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__time">19.5.17 __time</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The time function returns the current time in various formats.
</p>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>Format</td>
<td>
The format to be passed to SimpleDateFormat.
The function supports various shorthand aliases, see below.
</td>
<td>
No
</td>
</tr>
<tr>
<td>Name of variable</td>
<td>The name of the variable to set.
</td>
<td>
No
</td>
</tr>
</table>
</p>
<p>
If the format string is omitted, then the function returns the current time in milliseconds.
Otherwise, the current time is passed to SimpleDateFormat.
The following shorthand aliases are provided:
</p>
<ul>
<li>
YMD = yyyyMMdd
</li>
<li>
HMS = HHmmss
</li>
<li>
YMDHMS = yyyyMMdd-HHmmss
</li>
<li>
USER1 = whatever is in the Jmeter property time.USER1
</li>
<li>
USER2 = whatever is in the Jmeter property time.USER2
</li>
</ul>
<p>
The defaults can be changed by setting the appropriate JMeter property, e.g.
time.YMD=yyMMdd
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__jexl">19.5.18 __jexl</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The jexl function returns the result of evaluating a
<a href="http://jakarta.apache.org/commons/jexl">
Commons JEXL expression
</a>
.
See links below for more information on JEXL expressions.
</p>
<ul>
<li>
<a href="http://commons.apache.org/jexl/reference/syntax.html">
JEXL syntax description
</a>
</li>
<li>
<a href="http://commons.apache.org/jexl/reference/examples.html#Example_Expressions">
JEXL examples
</a>
</li>
</ul>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>Expression</td>
<td>
The expression to be evaluated. For example, 6*(5+2)
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Name of variable</td>
<td>The name of the variable to set.
</td>
<td>
No
</td>
</tr>
</table>
</p>
<p>
The following variables are made available to the script:
</p>
<ul>
<li>
ctx - JMeterContext object
</li>
<li>
vars - JMeterVariables object
</li>
<li>
props - JMeter Properties object
</li>
<li>
threadName - String
</li>
<li>
sampler - current Sampler object (if any)
</li>
<li>
sampleResult - previous SampleResult object (if any)
</li>
</ul>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__V">19.5.19 __V</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The V (variable) function returns the result of evaluating a variable name expression.
This can be used to evaluate nested variable references (which are not currently supported).
</p>
<p>
For example, if one has variables A1,A2 and N=1:
</p>
<ul>
<li>
${A1} - works OK
</li>
<li>
${A${N}} - does not work (nested variable reference)
</li>
<li>
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
</li>
</ul>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>Variable name</td>
<td>
The variable to be evaluated.
</td>
<td>
Yes
</td>
</tr>
</table>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__evalVar">19.5.20 __evalVar</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The eval function returns the result of evaluating an expression stored in a variable.
</p>
<p>
This allows one to read a string from a file, and process any variable references in it.
For example, if the variable "query" contains "select ${column} from ${table}"
and "column" and "table" contain "name" and "customers", then ${__evalVar(query)}
will evaluate as "select name from customers".
</p>
<p>
<b>Parameters</b>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th>Attribute</th><th>Description</th><th>Required</th></tr>
<tr>
<td>Variable name</td>
<td>
The variable to be evaluated.
</td>
<td>
Yes
</td>
</tr>
</table>
</p>
</td></tr>
<tr><td><br></td></tr>
</table>
<hr>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<font face="arial,helvetica,sanserif">
<h3><a name="__eval">19.5.21 __eval</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The eval function returns the result of evaluating a string expression.
</p>
<p>
This allows one to interpolate variable and function references in a strin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -