JMeter“if 控制器”带参数?

发布于 2024-11-01 21:24:20 字数 436 浏览 1 评论 0 原文

我正在阅读 JMeter 文档,并遇到了这个关于“If控制器”:

当条件被解释为 Javascript 时,脚本无法使用任何变量。如果您需要访问此类变量,请选择“将条件解释为变量表达式?”并使用 __javaScript() 函数调用。然后,您可以在脚本中使用对象“vars”、“log”、“ctx”等。

我不太明白这一点。这是否意味着如果我想访问“用户定义的参数”,那么我只能通过编写一些 JavaScript 来访问它?此框后面的示例引用“${COUNT}”

有人可以澄清 If 控制器的用法,也许可以举一两个示例吗?

I was reading the JMeter documentation and came across this info box about "If Controllers":

No variables are made available to the script when the condition is interpreted as Javascript. If you need access to such variables, then select "Interpret Condition as Variable Expression?" and use a __javaScript() function call. You can then use the objects "vars", "log", "ctx" etc. in the script.

I don't quite follow this. Does this mean if I want access to a "User Defined Parameter" then I can access it only by writing some JavaScript? The example that follows this box then refers to "${COUNT}"

Could someone clarify the usage of the If Controller, maybe with an example or two?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

等待我真够勒 2024-11-08 21:24:20

这些答案都是错误的!您需要将变量引用放在引号中,如下所示:

"${my_variable}"=="foo"

All these answers are wrong! You need to put the variable reference in quotes, like so:

"${my_variable}"=="foo"
-残月青衣踏尘吟 2024-11-08 21:24:20

您可以简单地使用类似

${my_variable}=='1'

有时 JMeter 文档可能会令人困惑:)

2017 年 9 月 27 日编辑:

这里的答案有效,但当线程数超过 40 时,会对性能产生非常糟糕的影响。 >

请参阅下面的正确且最有效的答案:

请参阅:

You can simply use something like

${my_variable}=='1'

Sometimes JMeter documentation can be confusing :)

Edit 27 september 2017:

The answer here works but has a very bad performance impact when number of threads exceeds 40.

See below for correct and most performing answer:

See:

流殇 2024-11-08 21:24:20

如果控制器将在内部使用 javascript 来评估条件,但这可能会降低性能。

更好的选项(从 JMeter 4 开始默认,请参阅 https://bz.apache .org/bugzilla/show_bug.cgi?id=61675) 是选中“将条件解释为变量表达式?”,然后在条件字段中有 2 个选项:

  • 选项 1 :使用包含 true 或 false 的变量。例如,如果您想测试最后一个样本是否成功,您可以使用

${JMeterThread.last_sample_ok}

如果控制器以 JMeter 3.4 开头

或任何您想要包含 true/false 的变量

${myVar}

  • 选项 2:使用函数 (${__jexl3()}建议)来计算必须返回 true 或 false 的表达式。
    例如,如果 COUNT 等于 1:

${__jexl3("${COUNT}"== "1",)}

${__jexl3(${COUNT}== 1,)}

如果控制器的表达式从 JMeter 3.4 开始

从 4.0 开始,如果不使用“将条件解释为变量表达式?”,则会出现红色警告显示:

如果控制器在 JMeter 3.4 中使用 javascript

如果您想了解有关 JMeter 和性能测试的更多信息 可以帮助你。

If Controller will internally use javascript to evaluate the condition but this can have a performance penalty.

A better option (default one starting from JMeter 4, see https://bz.apache.org/bugzilla/show_bug.cgi?id=61675) is to check "Interpret Condition as Variable Expression?", then in the condition field you have 2 options:

  • Option 1 : Use a variable that contains true or false. For example If you want to test if last sample was successful, you can use

${JMeterThread.last_sample_ok}

If Controller starting with JMeter 3.4

or any variable you want that contains true/false

${myVar}

  • Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false.
    For example if COUNT is equal to 1:

${__jexl3("${COUNT}"== "1",)}

OR

${__jexl3(${COUNT}== 1,)}

If Controller with expression starting with JMeter 3.4

Starting with 4.0, if you don't use the "Interpret Condition as Variable Expression?", a warning in RED will be displayed:

If Controller using javascript in JMeter 3.4

If you'd like to learn more about JMeter and performance testing this book can help you.

愿得七秒忆 2024-11-08 21:24:20

取消选中复选框
“将条件解释为变量表达式”

我浪费了几个小时而没有取消选中此复选框。无论语句末尾有或没有分号(;),它都可以工作。确保在调用 if 控制器之前已设置用户定义变量。

以下所有变体在 Jakarta Jmeter 1.5 中都对我有用

  • ${__javaScript("${HOMEPAGE}"=="Y")}
  • ${__javaScript("${HOMEPAGE}"=="Y")};
  • "${HOMEPAGE}"=="Y"
  • "${HOMEPAGE}"=="Y";

UNCHECK the CHECKBOX
"Interpret condition as variable expression"

I wasted a couple of hours without unchecking this checkbox. It worked with and without semicolon(;) at the end of the statement. Make sure that you have set the User-Defined Variables before calling the if controller.

All the following variations worked for me in Jakarta Jmeter 1.5

  • ${__javaScript("${HOMEPAGE}"=="Y")}
  • ${__javaScript("${HOMEPAGE}"=="Y")};
  • "${HOMEPAGE}"=="Y"
  • "${HOMEPAGE}"=="Y";
九厘米的零° 2024-11-08 21:24:20

上帝保佑http://habrahabr.ru
一直尝试直到找到这些。 在此处输入图像描述

使用引号是我的解决方案。

God bless the http://habrahabr.ru
Have tried until found these. enter image description here

Using the quotes was my solution.

站稳脚跟 2024-11-08 21:24:20

正如 Gerrie 所说,您需要检查变量

${my_var} == 'value'

,但要小心 '用户定义变量< /a>'

请注意,a 中的所有 UDV 元素
测试计划 - 无论他们在哪里 -
在开始时进行处理。

这基本上意味着您不能在“If 控制器”内定义“用户定义变量”。请查看“BeanShell”。

As Gerrie said you need to check your variable

${my_var} == 'value'

But be careful with the 'User Defined Variables'

Note that all the UDV elements in a
test plan - no matter where they are -
are processed at the start.

That basically means that you cannot define 'User Defined Variables' inside an 'If Controller'. Take a look to the 'BeanShell' instead.

心病无药医 2024-11-08 21:24:20

代替:
${my_variable}=='1'

“${my_variable}”==“1”

Replace:
${my_variable}=='1'
with
"${my_variable}" == "1"

給妳壹絲溫柔 2024-11-08 21:24:20

如果它的字符串值传递如下并且其性能有效

${__groovy("${key}"=="value")}

if it's string value pass as below and its performance effective

${__groovy("${key}"=="value")}

埋情葬爱 2024-11-08 21:24:20

检查图像

我已经在条件下使用了 ${code_g1}== 200 并且它有效我。

Check the image

I have used ${code_g1}== 200 in condition and it worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文