You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JMeter中基于前一个Sampler响应值控制采样器执行?

如何在JMeter中根据响应属性值分支执行不同请求?

Hey there! I’ve tackled this exact conditional flow in JMeter before, so let’s break down the steps to make this work for you:

1. 先从响应里提取要判断的属性值

First up, you need to pull the target property from your first Sampler’s response. The JSON Extractor is perfect for this:

  • Right-click your first Sampler → Add → Post Processors → JSON Extractor
  • In the JSON Path Expression field, enter the path to your target property. For example, if your response has an array property like "tags": [], use $.tags
  • Give it a Reference Name (something memorable like targetArrayProperty) so you can reference it later

2. 用If Controller实现分支判断

Next, add an If Controller to handle the "IF" case:

  • Right-click your Test Plan/Thread Group → Add → Logic Controller → If Controller
  • In the Condition box, paste this JEXL3 expression to check if the extracted value is exactly []:
    ${__jexl3("${targetArrayProperty}" == "[]",)}
    
    • JEXL3 is great for precise string comparisons here—make sure the quoted [] matches exactly what your response returns (no extra spaces!)

3. 添加IF分支的请求

Drag the Sampler you want to run only when the property is [] into this If Controller. It’ll only execute when the condition is true.

4. 设置ELSE分支的请求

For the "ELSE" case, add another If Controller with the inverse condition:

  • Create a second If Controller, and use this condition:
    ${__jexl3("${targetArrayProperty}" != "[]",)}
    
  • Drop your alternate Sampler into this second If Controller—it’ll run whenever the first condition fails.

Quick Notes to Avoid Headaches:

  • Always verify your extracted variable works first! Use the View Results Tree listener to check if ${targetArrayProperty} is correctly pulling [] (or the non-empty value) from the response
  • If your empty array might have whitespace (like [ ]), adjust the condition to match that exact string
  • If you’re dealing with a property that could be null instead of [], you’ll need to tweak the condition to account for that (e.g., combine with ${__isBlank(${targetArrayProperty},)})

内容的提问来源于stack exchange,提问作者Siddish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:40:27