Jmeter元件3 判断If Controller
Jmeter元件3 判断If Controller
一、IfController界面元素介绍
If Controller元素名称 | If Controller元素功能 |
Name | 定义If Controller名称 |
Comments | 注释 |
Condition(evaluated with javascript) | 定义条件表达式 |
Interpret Condition as Varible Expression |
如果勾选了 interpret condition as variable expression 只能判断表达式结果为true和false。要用Jmeter内置函数_jexl3或者_groovy 转换成true或者false 如果不勾选,则使用普通条件表达式判断。条件表达式结果可以是true\false之外的表达式。例如:${num} == 1 |
Evaluate for all childern |
勾选:表达式会在ifcontroller节点下的每个取样器之前执行一次,根据表达式结果判断是否执行该取样器 不勾选:只在ifcontroller入口处执行一次,根据结果判断是否执行下面的脚本。 |
二、 IfController实例
@ IfController应用场景
IfController控制器在实际的性能脚本场景中应用非常广泛,主要用来根据上个请求执行结果判断是否执行 IfController控制器里面的请求。
例如有两个请求:登录购物网站和添加购物车两个请求,判断当前用户是否登录网站,如果登录则执行下面的加入购物车请求,如果没有登录则不执行加入购物车请求。
@IfController实例
实例介绍:根据BeanShell Assertion断言判断访问网站首页是否成功,homePage=true 则执行IfController里面商品查询请求。homePage=false则不执行IfController里面商品查询请求。
@BeanShellAssertion断言变量为true\false类型
IfController判断断言中的homePage变量为true,(IfController勾选Interpret Condition as Varible Expression)执行查询商品请求。
@BeanShellAssertion断言homePage变量的值改为非true\false类型
IfController判断断言中的homePage变量为1,(IfController不勾选Interpret Condition as Varible Expression)执行查询商品请求。