内置函数

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

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

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

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

内置函数列表

函数类型函数名称函数说明
InformationthreadNumget thread number
InformationthreadGroupNameget thread group name
InformationsamplerNameget the sampler name (label)
InformationmachineIPget the local machine IP address
InformationmachineNameget the local machine name
Informationtimereturn current time in various formats
InformationtimeShiftreturn a date in various formats with the specified amount of seconds/minutes/hours/days added
Informationloglog (or display) a message (and return the value)
Informationlognlog (or display) a message (empty return value)
InputStringFromFileread a line from a file
InputFileToStringread an entire file
InputCSVReadread from CSV delimited file
InputXPathUse an XPath expression to read from a file
InputStringToFilewrite a string to a file
Calculationcountergenerate an incrementing number
FormattingdateTimeConvertConvert a date or time from source to target format
CalculationdigestGenerate a digest (SHA-1, SHA-256, MD5…)
CalculationintSumadd int numbers
CalculationlongSumadd long numbers
CalculationRandomgenerate a random number
CalculationRandomDategenerate random date within a specific date range
CalculationRandomFromMultipleVarsextracts an element from the values of a set of variables separated by |
CalculationRandomStringgenerate a random string
CalculationUUIDgenerate a random type 4 UUID
Scriptinggroovyrun an Apache Groovy script
ScriptingBeanShellrun a BeanShell script
ScriptingjavaScriptprocess JavaScript (Nashorn)
Scriptingjexl2evaluate a Commons Jexl2 expression
Scriptingjexl3evaluate a Commons Jexl3 expression
PropertiesisPropDefinedTest if a property exists
Propertiespropertyread a property
PropertiesPread a property (shorthand method)
PropertiessetPropertyset a JMeter property
VariablessplitSplit a string into variables
Variablesevalevaluate a variable expression
VariablesevalVarevaluate an expression stored in a variable
PropertiesisVarDefinedTest if a variable exists
VariablesVevaluate a variable name
Stringchargenerate Unicode char values from a list of numbers
StringchangeCaseChange case following different modes
StringescapeHtmlEncode strings using HTML encoding
StringescapeOroRegexpCharsquote meta chars used by ORO regular expression
StringescapeXmlEncode strings using XMl encoding
StringregexFunctionparse previous response using a regular expression
StringunescapeProcess strings containing Java escapes (e.g. \n & \t)
StringunescapeHtmlDecode HTML-encoded strings
StringurldecodeDecode a application/x-www-form-urlencoded string
StringurlencodeEncode a string to a application/x-www-form-urlencoded string
StringTestPlanNameReturn name of current test plan