jMeter-功能


jMeter-功能

JMeter函数和用户变量

JMeter函数是特殊的值,可以填充测试树中任何Sampler或其他元素的字段。

函数调用看起来像这样

${__functionName(var1,var2,var3)}
  • _functionName与函数名称匹配。例如$ {__ threadNum}。

  • 如果函数参数包含逗号,请确保使用“ \”对它进行转义,如下所示:

${__time(EEE\, d MMM yyyy)}

变量被称为

${VARIABLE}

功能清单

下表列出了一组松散地分为类型的功能

Function Type Name Comment
Information threadNum Get thread number.
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 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.
Calculation counter Generate an incrementing number.
Calculation intSum Add int numbers.
Calculation longSum Add long numbers.
Calculation Random Generate a random number.
Calculation RandomString Generate a random string.
Calculation UUID Generate a random type 4 UUID.
Scripting BeanShell Run a BeanShell script.
Scripting javaScript Process JavaScript (Mozilla Rhino).
Scripting jexl, jexl2 Evaluate a Commons Jexl expression.
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 V Evaluate a variable name.
Variables eval Evaluate a variable expression.
Variables evalVar Evaluate an expression stored in a variable.
String regexFunction Parse previous response using a regular expression.
String escapeOroRegexpChars Quote meta chars used by ORO regular expression.
String char Generate Unicode char values from a list of numbers.
String unescape Process strings containing Java escapes (e.g. \n & \t).
String unescapeHtml Decode HTML-encoded strings.
String escapeHtml Encode strings using HTML encoding.
String TestPlanName Return name of current test plan.
  • 有两种功能

    • 用户定义的静态值(或变量)

    • 内建功能

  • 用户定义的静态值允许用户定义在编译和提交要运行的测试树时用其静态值替换的变量。

  • 变量不能嵌套;即$ {Var $ {N}}不起作用。

  • V(变量)函数(2.2之后的版本)可用于执行此操作-$ { V(Var $ {N})}。

  • 没有功能也可以进行这种类型的替换,但是它不太方便且不直观。

在哪里使用函数和变量 函数和变量可以写入任何测试组件的任何字段中。

以下功能应在测试计划中正常运行

  • 求和
  • 长求和
  • 机器名
  • 豆壳
  • Java脚本
  • 杰克斯
  • 随机
  • 时间
  • 属性功能
  • 日志功能

测试计划中使用的功能有一些限制。在处理函数时,将不会完全设置JMeter线程变量,因此将不会设置作为参数传递的变量名,并且变量引用将不起作用。因此,split()和regex()以及变量评估函数将不起作用。该threadNum()函数将无法正常工作,它不会使在测试计划层次感。

引用变量和函数

  • 在测试元素中引用变量是通过将变量名括在'$ {'和'}'中来完成的。

  • 函数的引用方式相同,但按照惯例,函数名称以“__”开头,以避免与用户值名称冲突。

  • 一些函数使用参数来配置它们,这些参数用括号括起来,以逗号分隔。如果函数不带参数,则可以省略括号。例如

${__BeanShell(vars.put("name"\,"value"))}
  • 或者,您可以将脚本定义为变量,例如在“测试计划”上
SCRIPT     vars.put("name","value")
  • 然后可以如下引用脚本-
${__BeanShell(${SCRIPT})}

功能助手对话框

可从JMeter的“ 选项”选项卡中使用“功能帮助器”对话框。

  • 使用功能助手,您可以从下拉菜单中选择一个功能,并为其参数指定值。表的左列提供了该参数的简要说明,右列是您为该参数编写值的位置。不同的函数采用不同的参数。

  • 完成此操作后,单击“生成”按钮,将生成适当的字符串,您可以将其复制粘贴到测试计划中的任何位置。

预定义变量

JMeter在内部定义了一些变量。他们是

  • COOKIE_cookiename-包含cookie值。

  • JMeterThread.last_sample_ok-上一个样本是否正常-true / false。注意-在运行PostProcessors和Assertions之后,将对其进行更新。

  • START变量。

预定义属性

JMeter定义了一些内置属性。这些在下面列出。为方便起见,START属性也被复制到具有相同名称的变量。

  • START.MS-JMeter的开始时间(以毫秒为单位)。

  • START.YMD-JMeter的开始时间为yyyyMMdd。

  • START.HMS-JMeter的开始时间为HHmmss。

  • TESTSTART.MS-测试开始时间(以毫秒为单位)。

请注意,START变量/属性代表JMeter启动时间,而不是测试启动时间。它们主要用于文件名等。