跳转至

了解 FIT2CLOUD 飞致云旗下开源产品

内置函数

MeterSphere 接口测试基于 JMeter 实现,因此 JMeter 中的内置函数及变量在 MeterSphere 中都可以正常使用。内置函数及变量可以用在多个位置,包括QUERY参数、REST参数、请求体、前后置脚本等。

内置函数一般以两个下划线开头,并使用类似 ${__functionName(var1,var2,var3)} 的形式调用。

其中 __functionName 代表函数名,var1var2var3 分别是传给该函数的三个参数。

变量可以通过类似 ${varName} 的形式引用,其中 varName 代表变量名。

内置函数列表

函数类型 函数名称 函数说明
Information threadNum get thread number
Information threadGroupName get thread group name
Information samplerName get the sampler name (label)
Information machineIP get the local machine IP address
Information machineName get the local machine name
Information time return current time in various formats
Information timeShift return a date in various formats with the specified amount of seconds/minutes/hours/days added
Information log log (or display) a message (and return the value)
Information logn log (or display) a message (empty return value)
Input StringFromFile read a line from a file
Input FileToString read an entire file
Input CSVRead read from CSV delimited file
Input XPath Use an XPath expression to read from a file
Input StringToFile write a string to a file
Calculation counter generate an incrementing number
Formatting dateTimeConvert Convert a date or time from source to target format
Calculation digest Generate a digest (SHA-1, SHA-256, MD5...)
Calculation intSum add int numbers
Calculation longSum add long numbers
Calculation Random generate a random number
Calculation RandomDate generate random date within a specific date range
Calculation RandomFromMultipleVars extracts an element from the values of a set of variables separated by |
Calculation RandomString generate a random string
Calculation UUID generate a random type 4 UUID
Scripting groovy run an Apache Groovy script
Scripting BeanShell run a BeanShell script
Scripting javaScript process JavaScript (Nashorn)
Scripting jexl2 evaluate a Commons Jexl2 expression
Scripting jexl3 evaluate a Commons Jexl3 expression
Properties isPropDefined Test if a property exists
Properties property read a property
Properties P read a property (shorthand method)
Properties setProperty set a JMeter property
Variables split Split a string into variables
Variables eval evaluate a variable expression
Variables evalVar evaluate an expression stored in a variable
Properties isVarDefined Test if a variable exists
Variables V evaluate a variable name
String char generate Unicode char values from a list of numbers
String changeCase Change case following different modes
String escapeHtml Encode strings using HTML encoding
String escapeOroRegexpChars quote meta chars used by ORO regular expression
String escapeXml Encode strings using XMl encoding
String regexFunction parse previous response using a regular expression
String unescape Process strings containing Java escapes (e.g. \n & \t)
String unescapeHtml Decode HTML-encoded strings
String urldecode Decode a application/x-www-form-urlencoded string
String urlencode Encode a string to a application/x-www-form-urlencoded string
String TestPlanName Return name of current test plan