如何评估 bean shell 中的不等于?
How to evaluate not equals in bean shell?
我正在尝试在 bean shell 的 if 条件下评估不等于,但逻辑似乎是正确的。我没有得到预期的结果。
这是用于 bean shell post jmeter 中的处理器
r = ctx.getPreviousResult().getResponseCode();
if (!r.equals(200))
{
log.info("vin IS --> "+"${vin}");
p.println(r +","+ "${vin}" + ",");
}
我打算只打印非 200 响应代码,但它也打印 200 响应代码。
提前感谢您的帮助
代码:
if (!r.equals(200))
应该是:
if (!r.equals("200"))
顺便说一句,你不应该再使用 Beanshell,更喜欢 JSR223 测试元素 + Groovy 按照这个 :
您正在比较 String with an Integer,您需要先将其转换为整数,例如:
r = Integer.parseInt(ctx.getPreviousResult().getResponseCode());
- 您使用的是 some form of performance anti-pattern. It's recommended to use JSR223 Test Elements and Groovy language for any form of scripting as Groovy has much better performance comparing to Beanshell.
的 Beanshell
您正在内联 JMeter Variables into scripts, it is not very safe as variables might resolve into something which cause compilation failure or unexpected behavior. Moreover in case of Groovy variables will either be resolved only once or clash with GString templates / compilation caching 功能。所以考虑改变:
log.info("vin IS --> "+"${vin}");
至
log.info("vin IS --> "+vars.get("vin"));
我正在尝试在 bean shell 的 if 条件下评估不等于,但逻辑似乎是正确的。我没有得到预期的结果。
这是用于 bean shell post jmeter 中的处理器
r = ctx.getPreviousResult().getResponseCode();
if (!r.equals(200))
{
log.info("vin IS --> "+"${vin}");
p.println(r +","+ "${vin}" + ",");
}
我打算只打印非 200 响应代码,但它也打印 200 响应代码。
提前感谢您的帮助
代码:
if (!r.equals(200))
应该是:
if (!r.equals("200"))
顺便说一句,你不应该再使用 Beanshell,更喜欢 JSR223 测试元素 + Groovy 按照这个 :
您正在比较 String with an Integer,您需要先将其转换为整数,例如:
r = Integer.parseInt(ctx.getPreviousResult().getResponseCode());
- 您使用的是 some form of performance anti-pattern. It's recommended to use JSR223 Test Elements and Groovy language for any form of scripting as Groovy has much better performance comparing to Beanshell. 的 Beanshell
您正在内联 JMeter Variables into scripts, it is not very safe as variables might resolve into something which cause compilation failure or unexpected behavior. Moreover in case of Groovy variables will either be resolved only once or clash with GString templates / compilation caching 功能。所以考虑改变:
log.info("vin IS --> "+"${vin}");
至
log.info("vin IS --> "+vars.get("vin"));