jmeter斷言接口響應字段大小


 

一,有時候斷言需要判斷接口返回某個字段值是否大於或者小於預期值,此時斷言需要用到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提取出該值進行進行判斷

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM