在测试过程中,我们会遇到这样的场景,当某个接口a返回任务或者订单号的ID时,另一个接口b需要调用a接口的任务ID或订单号,如果a接口返回的任务或者订单号的ID为null时,b接口运行会报错,此时,我们就需要(If)控制器来判断接口a的响应结果是否为null,来控制接口b的运行。
首先我们看看 Jmeter官网的解释:
The If Controller allows the user to control whether the test elements below it (its children) are run or not.
By default, the condition is evaluated only once on initial entry, but you have the option to have it evaluated for every runnable element contained in the controller.
元件(If)控制器添加路径
(If)控制器界面
(If)控制器使用场景:
- Option 1 : Use a variable that contains true or false
If you want to test if last sample was successful, you can use
${JMeterThread.last_sample_ok} - Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false
我们看看jmeter官网的例子: - ${__groovy(vars.get(“myVar”) != “Invalid” )} (Groovy check myVar is not equal to Invalid)
- ${__groovy(vars.get(“myInt”).toInteger() <=4 )} (Groovy check myInt is less then or equal to 4)
- ${__groovy(vars.get(“myInt”).toInteger() <=4 )} (Groovy check myInt is less then or equal to 4)
- KaTeX parse error: Expected group after '_' at position 2: {_̲_jexl3({COUNT} < 10)}
- ${RESULT}
- ${JMeterThread.last_sample_ok} (check if the last sample succeeded)
OK(If)控制器的使用我们就分享至此,谢谢!