首页 > 解决方案 > Beanshell 函数在 if/else 评估之前被调用

问题描述

我创建了 2 个 BeanShell 函数 myFoo1 和 myFoo2。

第一个函数应在特定条件下执行,第二个函数应在不同条件下执行

问题是在我的 JSR223Post Processor 或 BeanPost Processor

String code = ctx.getPreviousResult().getResponseCode();
if (code.contains("200") && (vars.get("abc1") != "Howdee")) {
    ${__BeanShell(myFoo1("print this"))}

}
else {
    ${__BeanShell(myFoo2("print this"))}
}

问题是 beanShell 函数 myFoo1 和 myFoo2 在 if/else 评估之前被调用。

换句话说,myFoo1 和 myFoo2 它们都被一个接一个地调用,并且 if/else 从来没有任何效果,所以看起来 Bean 函数调用是在任何评估之前执行的。我该如何解决?

标签: jmeter

解决方案


${__BeanShell(从脚本中删除并直接调用它myFoo2("print this)

String code = ctx.getPreviousResult().getResponseCode();
if (code.contains("200") && (vars.get("abc1") != "Howdee")) {
    myFoo1("print this);

}
else {
    myFoo2("print this);
}

推荐阅读