跳到主要内容

内置函数

1 内置函数概述​

MeterSphere 接口测试基于 JMeter 实现,因此 JMeter 中的内置函数及变量在 MeterSphere 中都可以正常使用。内置函数及变量可应用于QUERY 参数、REST 参数、请求体、前后置脚本等。
内置函数一般以两个下划线开头,并使用类似 ${__functionName(var1,var2,var3)} 的形式调用。其中 __functionName 代表函数名,var1,var2 和 var3 分别是传给该函数的三个参数。
变量可以通过类似 ${varName} 的形式引用,其中 varName 代表变量名。例如:生成1到100的随机数使用表达式:${__Random(1,100)}。

2 内置函数列表​

函数类型函数名称函数说明
Information threadNumget thread number
Information threadGroupNameget thread group name
Information samplerNameget the sampler name (label)
Information machineIPget the local machine IP address
Information machineNameget the local machine name
Information timereturn current time in various formats
Information timeShiftreturn a date in various formats with the specified amount of seconds/minutes/hours/days added
Information loglog (or display) a message (and return the value)
Information lognlog (or display) a message (empty return value)
Input StringFromFileread a line from a file
Input FileToStringread an entire file
Input CSVReadread from CSV delimited file
Input XPathUse an XPath expression to read from a file
Input StringToFilewrite a string to a file
Calculation countergenerate an incrementing number
Formatting dateTimeConvertConvert a date or time from source to target format
Calculation digestGenerate a digest (SHA-1, SHA-256, MD5...)
Calculation intSumadd int numbers
Calculation longSumadd long numbers
Calculation Randomgenerate a random number
Calculation RandomDategenerate random date within a specific date range
Calculation RandomFromMultipleVarsextracts an element from the values of a set of variables separated by |
Calculation RandomStringgenerate a random string
Calculation UUIDgenerate a random type 4 UUID
Scripting groovyrun an Apache Groovy script
Scripting BeanShellrun a BeanShell script
Scripting javaScriptprocess JavaScript (Nashorn)
Scripting jexl2evaluate a Commons Jexl2 expression
Scripting jexl3evaluate a Commons Jexl3 expression
Properties isPropDefined Test if a property exists
Properties property read a property
Properties Pread a property (shorthand method)
Properties setPropertyset a JMeter property
Variables splitSplit a string into variables
Variables evalevaluate a variable expression
Variables evalVarevaluate an expression stored in a variable
Properties isVarDefined Test if a variable exists
Variables Vevaluate a variable name
String chargenerate Unicode char values from a list of numbers
String changeCaseChange case following different modes
String escapeHtmlEncode strings using HTML encoding
String escapeOroRegexpCharsquote meta chars used by ORO regular expression
String escapeXmlEncode strings using XMl encoding
String regexFunctionparse previous response using a regular expression
String unescapeProcess strings containing Java escapes (e.g. \n & \t)
String unescapeHtmlDecode HTML-encoded strings
String urldecodeDecode a application/x-www-form-urlencoded string
String urlencodeEncode a string to a application/x-www-form-urlencoded string
String TestPlanNameReturn name of current test plan