📄 functions.html
字号:
<p>
Each thread has its own internal pointer to its current row in the file array.
When a thread first refers to the file it will be allocated the next free row in
the array, so each thread will access a different row from all other threads.
[Unless there are more threads than there are rows in the array.]
</p>
<p>
Note: the function splits the line at every comma by default.
If you want to enter columns containing commas, then you will need
to change the delimiter to a character that does not appear in any
column data, by setting the property: csvread.delimiter
</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>File Name</td>
<td>The file (or *ALIAS) to read from
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Column number</td>
<td>
The column number in the file.
0 = first column, 1 = second etc.
"next" - go to next line of file.
*ALIAS - open a file and assign it to the alias
</td>
<td>
Yes
</td>
</tr>
</table>
</p>
<p>
For example, you could set up some variables as follows:
<ul>
<li>
COL1a ${__CSVRead(random.txt,0)}
</li>
<li>
COL2a ${__CSVRead(random.txt,1)}${__CSVRead(random.txt,next)}
</li>
<li>
COL1b ${__CSVRead(random.txt,0)}
</li>
<li>
COL2b ${__CSVRead(random.txt,1)}${__CSVRead(random.txt,next)}
</li>
</ul>
This would read two columns from one line, and two columns from the next available line.
If all the variables are defined on the same User Parameters Pre-Processor, then the lines
will be consecutive. Otherwise, a different thread may grab the next line.
</p>
<p><table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
<tr><td>
The function is not suitable for use with large files, as the entire file is stored in memory.
For larger files, use
<a href="component_reference.html#CSV_Data_Set_Config">
CSV Data Set Config element
</a>
or
<a href="#__StringFromFile">
StringFromFile
</a>
.
</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="__property">19.5.9 __property</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The property function returns the value of a JMeter property.
If the property value cannot be found, and no default has been supplied, it returns the property name.
When supplying a default value, there is no need to provide a function name - the parameter can be set to null, and it will be ignored.
</p>
For example:
<p>
<ul>
<li>
${__property(user.dir)} - return value of user.dir
</li>
<li>
${__property(user.dir,UDIR)} - return value of user.dir and save in UDIR
</li>
<li>
${__property(abcd,ABCD,atod)} - return value of property abcd (or "atod" if not defined) and save in ABCD
</li>
<li>
${__property(abcd,,atod)} - return value of property abcd (or "atod" if not defined) but don't save it
</li>
</ul>
</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 retrieved.
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Variable Name</td>
<td>A reference name for reusing the value
computed by this function.
</td>
<td>
No
</td>
</tr>
<tr>
<td>Default Value</td>
<td>The default value for the property.
</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="__P">19.5.10 __P</h3></a>
</font>
</td></tr>
<tr><td>
<p>
This is a simplified property function which is
intended for use with properties defined on the command line.
Unlike the __property function, there is no option to save the value in a variable,
and if no default value is supplied, it is assumed to be 1.
The value of 1 was chosen because it is valid for common test variables such
as loops, thread count, ramp up etc.
</p>
For example:
<p>
<code>
Define the property value:
<br>
</br>
jmeter -Jgroup1.threads=7 -Jhostname1=www.realhost.edu
<br>
</br>
Fetch the values:
<br>
</br>
${__P(group1.threads)} - return the value of group1.threads
<br>
</br>
${__P(group1.loops)} - return the value of group1.loops
<br>
</br>
${__P(hostname,www.dummy.org)} - return value of property hostname or www.dummy.org if not defined
<br>
</br>
</code>
In the examples above, the first function call would return 7,
the second would return 1 and the last would return www.dummy.org
(unless those properties were defined elsewhere!)
</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 retrieved.
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Default Value</td>
<td>The default value for the property.
If omitted, the default is set to "1".
</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="__log">19.5.11 __log</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The log function logs a message, and returns its input string
</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>String to be logged</td>
<td>A string
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Log Level</td>
<td>OUT, ERR, DEBUG, INFO (default), WARN or ERROR
</td>
<td>
No
</td>
</tr>
<tr>
<td>Throwable text</td>
<td>If non-empty, creates a Throwable to pass to the logger
</td>
<td>
No
</td>
</tr>
<tr>
<td>Comment</td>
<td>If present, it is displayed in the string.
Useful for identifying what is being logged.
</td>
<td>
No
</td>
</tr>
</table>
</p>
<p>
The OUT and ERR log level names are used to direct the output to System.out and System.err respectively.
In this case, the output is always printed - it does not depend on the current log setting.
</p>
<pre>
For example:
${__log(Message)} - written to the log file as "...thread Name : Message"
${__log(Message,OUT)} - written to console window
${__log(${VAR},,,VAR=)} - written to log file as "...thread Name VAR=value"
</pre>
</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="__logn">19.5.12 __logn</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The logn function logs a message, and returns the empty string
</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>String to be logged</td>
<td>A string
</td>
<td>
Yes
</td>
</tr>
<tr>
<td>Log Level</td>
<td>OUT, ERR, DEBUG, INFO (default), WARN or ERROR
</td>
<td>
No
</td>
</tr>
<tr>
<td>Throwable text</td>
<td>If non-empty, creates a Throwable to pass to the logger
</td>
<td>
No
</td>
</tr>
</table>
</p>
<p>
The OUT and ERR log level names are used to direct the output to System.out and System.err respectively.
In this case, the output is always printed - it does not depend on the current log setting.
</p>
<pre>
For example:
${__logn(VAR1=${VAR1},OUT)} - write the value of the variable to the console window
</pre>
</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="__BeanShell">19.5.13 __BeanShell</h3></a>
</font>
</td></tr>
<tr><td>
<p>
The BeanShell function evaluates the script passed to it, and returns the result.
</p>
<p>
<b>
Please note that the BeanShell jar file is not included with JMeter; it needs to be separately downloaded.
<br>
</br>
For full details on using BeanShell, please see the BeanShell web-site at
<a href="http://www.beanshell.org/">
http://www.beanshell.org/
</a>
</b>
</p>
<p>
Note that a different Interpreter is used for each independent occurence of the function
in a test script, but the same Interpreter is used for subsequent invocations.
This means that variables persist across calls to the function.
</p>
<p>
A single instance of a function may be called from multiple threads.
However the function execute() method is synchronised.
</p>
<p>
If the property "beanshell.function.init" is defined, it is passed to the Interpreter
as the name of a sourced file. This can be used to define common methods and variables. There is a
sample init file in the bin directory: BeanShellFunction.bshrc.
</p>
<p>
The following variables are set before the script is executed:
<ul>
<li>
log - the logger for the BeanShell function (*)
</li>
<li>
ctx - the current JMeter context variable
</li>
<li>
vars - the current JMeter variables
</li>
<li>
props - JMeter Properties object
</li>
<li>
threadName - the threadName
</li>
<li>
Sampler the current Sampler, if any
</li>
<li>
SampleResult - the current SampleResult, if any
</li>
</ul>
(*) means that this is set before the init file, if any, is processed.
Other variables vary from invocation to invocation.
</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>BeanShell script</td>
<td>A beanshell script (not a file name)
</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>
No
</td>
</tr>
</table>
</p>
<p>
Example:
<pre>
${__BeanShell(123*456)} - returns 56088
${__BeanShell(source("function.bsh"))} - processes the script in function.bsh
</pre>
</p>
<p><table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
<tr><td>Remember to include any necessary quotes for text strings and JMeter variables
</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="__split">19.5.14 __split</h3></a>
</font>
</td></tr>
<tr><td>
<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -