Jmeter BeanShell PreProcessor的使用笔记
1.打印log
log.info("content:" + content);
2. 将字符串转化为JsonString
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
String content = "{\"businessCode\":\"r2\",\"channelCode\":\"MOCK\",\"realName\":\"r1\",\"idCard\":\"r4\",\"userMobile\":\"r5\",\"bankMobile\":\"r5\",\"bankCardNo\":\"r3\",\"bankOfDeposit\":\"浦发银行\",\"purpose\":\"Test收款\",\"amount\":0.01,\"currency\":\"CNY\"}".replace("r1", vars.get("name")).replace("r2", vars.get("businessCode")).replace("r3", vars.get("bankCard")).replace("r4", vars.get("idCard")).replace("r5", vars.get("mobile"));
System.out.println(content);
JSONObject object = JSON.parseObject(content);
String content_json = object.toString();
3. 给变量赋值
vars.put("bankCard", bankCard);
4. 获取变量的值
vars.get("bankCard", bankCard);
6. 给字符串md5加密
import org.apache.commons.codec.digest.DigestUtils;
String sign = DigestUtils.md5Hex("StringObject");
7. 获取接口返回信息
String response = prev.getResponseDataAsString();
int statusCode = prev.getResponseCode();
Stirng urlString = prev.getUrlAsString();
getResponseMessage();
getRequestHeaders();
getMediaType();
getBodySizeAsLong(); 获取Body大小
getDataEncodingWithDefault();
isResponseCodeOK();