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

相关文章
相关标签/搜索