51Testing软件测试论坛
标题:
vars.put 赋值失败,在调用beanshell preprocessor相关api之后
[打印本页]
作者:
kernelkoder
时间:
2019-12-30 09:40
标题:
vars.put 赋值失败,在调用beanshell preprocessor相关api之后
本帖最后由 kernelkoder 于 2019-12-30 09:45 编辑
我的测试需要根据当前http请求参数计算sha1签名,用到了beanshell preprocessorfollowing is beanshell preprocessor source code
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Collection;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.commons.codec.digest.DigestUtils;
Date date = new Date();
long time = (date.getTime());
String s = String.valueOf(time);
vars.put("timestamp1",s);
Arguments args = sampler.getArguments();
log.info(String.valueOf(args.getArgumentCount()));
Map reqMap = args.getArgumentsAsMap();
reqMap.put("sign_key","123");
reqMap.put("client_id","456");
ArrayList arrlist=new ArrayList();
for(String key:reqMap.keySet()){
log.info( "key: "+ key + " and value: "+ reqMap.get(key));
if(key.equals("sign") || key.equals("access_token"))
{
continue;
}
arrlist.add(key);
}
Collections.sort(arrlist);
String sign="";
for(int i=0;i<arrlist.size();i++)
{
String key=(String)arrlist.get(i);
sign+=key;
sign+=(String)reqMap.get(key);
}
log.info(sign);
String final_sign=DigestUtils.sha1Hex(sign);
log.info(final_sign);
vars.put("sign1",final_sign);
复制代码
在jmeter GET请求 form中有一个变量 'sign', with value of ${sign1}, 我的意图是用最后的代码把var.put("sign1" , final_sign),把计算好的final_sign,赋值给form里面的那个变量的值.
但是,有问题,我发现,每次调用jemter 相关的api,最后的"vars.put("sign1",final_sign)" 会失效导致最后出去的http请求还是 http....sign={sign1}... 没有被替换掉
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2