1、添加计数器——用户区分导出的文件名称
2、添加Bean Shell PostProcessor元件
3、编写Bean Shell脚本——用户将导出的excel保存到本地(原浏览器的工作)
脚本内容如下:
//JMeter的内置API:prev.getResponseData()获取请求的响应内容
byte[] responseData = prev.getResponseData();
//导出的excel存放位置
private String filePath = "D:/tools/apache-jmeter-2.10/bin/base_base/导出-${index}.xls";
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File file = new File(filePath);
fos = new FileOutputStream(file); //不添加参数true,以非追加的方式添加内容
bos = new BufferedOutputStream(fos);
bos.write(responseData);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
注意:Synchronizing Timer控件——在这里进行并发控制
运行结果,导出-01.xls----》导出了全部内容
导出-001.xls----》导出了选中的内容