jmeter 线程组之间的参数传递(加密接口测试三)

场景测试中,一次登录后做多个接口的操作,然后登录后的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);




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);

  

猜你喜欢

转载自www.cnblogs.com/xiaohuhu/p/10754383.html