jmeter bean shell斷言加密的響應信息(加密接口測試二)

一、在http請求-->添加-->斷言-->bean shell 斷言shell

import com.changfu.EncryptAndDecryptInterface;  //導入jar包的EncryptAndDecryptInterface類
import org.json.JSONObject; //導入
String json_res = prev.getResponseDataAsString(); //獲取上個響應信息
String resb = EncryptAndDecryptInterface.getDecrypt(json_res);  //調用解密工具解密
vars.put("resb",resb);  
log.info("解密後的響應信息json="+resb);
JSONObject resbonseJson = new JSONObject(resb); //解析json
String status_str = resbonseJson.get("status").toString(); //截取status字段值
vars.put("status_str",status_str);
log.info("執行狀態="+status_str);
String result = "0";
vars.put("result_str",result);
if (!status_str.equals(result)) {   //響應信息的狀態值status_str不等於0,則斷言其餘與實際值不一致
    Failure=true;       
    FailureMessage="statuscode與實際值不一致, 實際值爲:"+status_str+", 響應信息: "+resb;
}json

 

 

相關文章
相關標籤/搜索