下面我写的是获取response中的token值写入excel中
1、要获取的http请求的response内容为:
jmeter:将response的“token”内容写入excel

2、选中要获取response内容的http请求,点击鼠标右键,选择【添加】-【后置处理器】-【BeanShell PostProcessor】
jmeter:将response的“token”内容写入excel
3、在jmeter的安装目录下的【lib】目录中放入fastjson-1.2.47.jar
jmeter:将response的“token”内容写入excel
4、在【BeanShell PostProcessor】中写入以下内容

import com.alibaba.fastjson.JSONObject;
//备注:BeanShell PostProcessor中代码如下:
//JMeter的内置API:prev.getResponseData()获取请求的响应内容
byte[] responseData = prev.getResponseData(); 

//①仅以文件名作为filepath的值,则导出的文件会默认保存在Jmeter安装路径的bin(即JVM的启动路径);
//private String filePath = "${ExportExcelName}";

//②指定绝对路径
private String filePath = "C:/Users/admin/Desktop/jmeterTest/xx.csv";   //存放response内容的csv路径

BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
	JSONObject json =JSONObject.parseObject(new String(responseData));
	String token_=json.getJSONObject("data").getString("token")+",";
		BufferedWriter out = null;
		try {
		out = new BufferedWriter(new OutputStreamWriter(
		new FileOutputStream(filePath, true)));
		out.write(token_+"\r\n");
		} catch (Exception e) {
		e.printStackTrace();
		} finally {
		try {
		out.close();
		} catch (IOException e) {
		e.printStackTrace();
		}
		}

4、运行该http请求的线程组,生成的xx.csv如下:
jmeter:将response的“token”内容写入excel

jmeter:将response的“token”内容写入excel

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-27
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案