JMeter 检查状态是否为 200

JMeter check if status is 200

在我的测试计划中,我有 2 个端点 bidwin。如果bid端点return状态200(它也可以return204,但我只需要200所以我不能使用${JMeterThread.last_sample_ok})我需要运行 win端点。 我做到了:

  1. 创建定义变量STATUS_OK

  2. bid 请求下创建正则表达式提取器以获取响应代码 :

  3. 添加If controller并在该控制器下插入win请求:

但是 if controller 条件不工作,Jmeter 从不 运行 win 请求。

知道为什么它不起作用吗?或者我可以调试它吗?如有任何帮助,我将不胜感激!!!

已更新,包括测试计划结构:

对于 If Controller 你应该使用 __groovy 或 __jexl3 函数来代替

Interpret Condition as Variable Expression? If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored). For example, ${FOUND} or ${__jexl3(${VAR} > 100)}. Unlike the JavaScript case, the condition is only checked to see if it matches "true" (case is ignored). Checking this and using __jexl3 or __groovy function in Condition is advised for performances

在你的情况下使用

${__groovy(vars.get("BID_STATUS") == vars.get("STATUS_OK") )}

或者

${__jexl3("${BID_STATUS}" == "${STATUS_OK}")}

您需要用引号将 JMeter 变量引用括起来,例如:

"${BID_STATUS}" == "${STATUS_OK}"

或者(更好)您可以摆脱这个正则表达式提取器并切换 If Controller 的条件以使用 __groovy() function,例如:

${__groovy(prev.getResponseCode().equals(vars.get('STATUS_OK')),)}

更多信息:Apache Groovy - Why and How You Should Use It