1. 程式人生 > >jmeter bean shell斷言加密的響應資訊(加密介面測試二)

jmeter bean shell斷言加密的響應資訊(加密介面測試二)

斷言加密的響應資訊

1、在http請求-->新增-->斷言-->bean 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;
}

 

 

轉蝸牛:https://www.cnblogs.com/wnfindbug/p/5817114.html