jmeter BeanShell PostProcessor 获取http请求的入参,存入CSV
1、在http请求前新建一个jmeter BeanShell PostProcessor,其与http请求同在一个线程组内。

2、下载fastjson-2.0.14.jar包放在jmeter的lib目录下

下载路径为:https://mvnrepository.com/artifact/com.alibaba/fastjson/2.0.14
3、测试计划加载fastjson-2.0.14.jar包

4、BeanShell PostProcessor插件写如下代码,用于获取入参里的fund_account和ext_txn_reference,并存入CSV:
import org.json.*;
import com.alibaba.fastjson.*;
import java.io.*;
//获取接口中的请求参数
String request=ctx.getCurrentSampler().getArguments().getArgument(0).getValue();
log.info("request is:"+request);
//将请求参数转为JSON格式
JSONObject data_obj=JSON.parseObject(request);
//拿到指定入参
String data_1=data_obj.getString("fund_account");
log.info("fund_account is: "+data_1);
String data_2=data_obj.getString("ext_txn_reference");
log.info("ext_txn_reference is: "+data_2);
FileWriter file=new FileWriter("D:\\456.csv",true);
BufferedWriter out = new BufferedWriter(file);
out.write(data_1+','+data_2+"\n");
out.close();
file.close();
下图所示即为入参:

下图所示即为代码:

下图所示即为存在CSV的数据:

浙公网安备 33010602011771号