如何将用户定义变量的值放入Bean shell Sampler Variable - Jmeter
How to put value of User Defined Variable into Bean shell Sampler Variable - Jmeter
我尝试将用户定义的变量移动到 beanshell 采样器中的变量。
(我需要用户定义的变量成为更大字符串的一部分。)
当我尝试移动它或复制它时,出现错误 500
有人可以告诉我如何将用户定义字段的值放入 bean-shell 变量中然后使用它(不需要更改用户定义的变量只需要它的值)
在此脚本中,我想将 $Expected_Offer_ID 的值放入字符串变量 Expected_Offer
JMeter变量通过vars
对象访问,使用:
String Expected_Offer = vars.get("Expected_Offer");
有(至少)2个选项:
- 将
${Expected_Offer_ID}
放入采样器的 "Parameter" 部分。您将能够在脚本 中以 Parameters
的形式访问它
- 在需要时使用
vars.get("Expected_Offer_ID);
。 vars
是一个 shorthand 到 JMeterVariables class 实例,它提供 read/write 访问所有 JMeter 变量
记住两件事:
- 从不 引用 JMeter Variables and/or Functions in the Script body like
${myVar}
, either use aforementioned "Parameters" section or code-based equivalents as they might resolve into something which can cause script interpretation failure or unexpected behaviour. Moreover, in case of Groovy 语言它阻止编译脚本缓存
- 不要使用 Beanshell 编写脚本。自 JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language as Groovy is more Java-compliant and performs much better. See Apache Groovy - Why and How You Should Use It 文章以来,有关 Groovy JDK 增强功能的更详细解释、基准测试和一些提示。
我尝试将用户定义的变量移动到 beanshell 采样器中的变量。 (我需要用户定义的变量成为更大字符串的一部分。)
当我尝试移动它或复制它时,出现错误 500
有人可以告诉我如何将用户定义字段的值放入 bean-shell 变量中然后使用它(不需要更改用户定义的变量只需要它的值)
在此脚本中,我想将 $Expected_Offer_ID 的值放入字符串变量 Expected_Offer
JMeter变量通过vars
对象访问,使用:
String Expected_Offer = vars.get("Expected_Offer");
有(至少)2个选项:
- 将
${Expected_Offer_ID}
放入采样器的 "Parameter" 部分。您将能够在脚本 中以 - 在需要时使用
vars.get("Expected_Offer_ID);
。vars
是一个 shorthand 到 JMeterVariables class 实例,它提供 read/write 访问所有 JMeter 变量
Parameters
的形式访问它
记住两件事:
- 从不 引用 JMeter Variables and/or Functions in the Script body like
${myVar}
, either use aforementioned "Parameters" section or code-based equivalents as they might resolve into something which can cause script interpretation failure or unexpected behaviour. Moreover, in case of Groovy 语言它阻止编译脚本缓存 - 不要使用 Beanshell 编写脚本。自 JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language as Groovy is more Java-compliant and performs much better. See Apache Groovy - Why and How You Should Use It 文章以来,有关 Groovy JDK 增强功能的更详细解释、基准测试和一些提示。