場景測試中,一次登錄后做多個接口的操作,然后登錄后的uid需要關聯傳遞給其他接口發送請求的時候使用。
1、在登錄接口響應信息中提取uid字段值
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);
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);
2、在測試計划中添加“用戶參數”
需要傳遞的參數添加到用戶參數
3、在另一個線程組接收該變量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);
String uid_str = props.get("uid_str"); //獲取登錄傳遞的uid_str變量
String enuid=EncryptAndDecryptInterface.getEncryptUID(uid_str); //加密登錄返回的uid
vars.put("enuid",enuid);
log.info("加密登錄后返回的uid"+enuid);
