6.beanshell 断言的使用
当遇到复杂的业务场景时,简单的断言已不足以应对,此时需要Beanshell 断言组件
示例:
例如,判断接口响应结果字段responseCode为650,69,659,999,990开头时时,那么认为它就是异常的
创建beanshell 断言组件
String res_msg = SampleResult.getResponseDataAsString();
if (res_msg.indexOf(\"responseCode\":\"650\") ! = -1 ||res_msg.indexOf(\"responseCode\":\"69\") ! = -1|| res_msg.indexOf(\"responseCode\":\"659\") ! = -1 || res_msg.indexOf(\"responseCode\":\"999\") ! = -1 || res_msg.indexOf(\"responseCode\":\"990\") ! = -1 )
{
SampleResult.setSuccessful(false);
Failure = true;
FailureMessage = res_msg;
}
else
{
SampleResult.setSuccessful(true);
Failure = false;
FailureMessage = res_msg;
}
vars.put("FailureMessage",FailureMessage );