一,有時候斷言需要判斷接口返回某個字段值是否大於或者小於預期值,此時斷言需要用到BeanShell斷言
寫法如下:
import com.alibaba.fastjson.JSONObject;
// String expiresin=vars.get("body.expiresin");
String resp = prev.getResponseDataAsString();
JSONObject respJson = new JSONObject(resp);
int expiresin = respJson.get("body").getInteger("expiresin");
if(expiresin > =0){
Failure = false;
}else{
Failure = true;
FailureMessage = "失敗, " + expiresin + "不 >= 0 ";
}
二、添加依賴包fastjson
三、添加BeanShell斷言控件
斷言內容為接口返回expiresin字段,需要用fastjson提取出該值進行進行判斷