jmeter 線程組之間的參數傳遞(加密接口測試三)

場景測試中,一次登陸後作多個接口的操做,而後登陸後的uid須要關聯傳遞給其餘接口發送請求的時候使用。shell

一、在登陸接口響應信息中提取uid字段值json

  1>login請求 -->添加 -->後置處理器--> bean shell postprocessor工具

 
  2>在bean shell postprocessor提取uid
 
import com.changfu.EncryptAndDecryptInterface;
import org.json.JSONArray;
import org.json.JSONObject;

String json_res = prev.getResponseDataAsString(); //獲取登陸請求的響應信息
String resb = EncryptAndDecryptInterface.getDecrypt(json_res);  //調用解密工具解密,對響應信息解密
vars.put("resb",resb);  
log.info("解密後的響應信息resb="+resb);
JSONObject data_obj = new JSONObject(resb);   //解析json響應信息

String uid_str = data_obj.get("result").get("id").toString();  //截取響應信息中uid的值
props.put("uid_str",uid_str);   //將uid_str數據存到變量中,這裏用props.put,其餘線程組可調用請該變量
log.info("加密前的uid="+uid_str);




二、在測試計劃中添加「用戶參數」
 
 
須要傳遞的參數添加到用戶參數
 
三、在另外一個線程組接收該變量uid_str
  1>線程組->添加-->前置處理器-->BeanShell PreProcessor
import com.changfu.EncryptAndDecryptInterface;

String uid_str = props.get("uid_str"); //獲取登陸傳遞的uid_str變量
String enuid=EncryptAndDecryptInterface.getEncryptUID(uid_str);  //加密登陸返回的uid
vars.put("enuid",enuid);
log.info("加密登陸後返回的uid"+enuid);

相關文章
相關標籤/搜索