JMeter测试导入接口
利用Jmeter测试上传文件,首先可根据接口文档或者fiddler抓包分析文件上传的接口;如下图:
以下是我通过fiddler所截取的文件上传的接口

1、填写导入接口的信息

查看文件上传栏下的填写信息:
文件名称:导入文件的路径
参数名称:file
MIME类型:为fiddler抓包的Content-Type的值;如下图
2、然后就要填写post的内容,此时再看抓包截取的请求内容,如图

3、此时,添加结果树,查看响应报文,一直报文件不存在

4、查了许多资料,有可能是因为文件上传路径的'\'被编码了,服务器无法识别
此时,需在http request 设置 implementation 为 Java ,让请求内容不被编码,如图

5、执行结果;查看响应正常和fiddler抓包的响应是一样的;

JMeter测试导出接口到本地
1、新建线程组-http请求,如图 (bean shell脚本见步骤3)

2、如导出接口需要有token校验,可在HTTP信息头管理器中添加token信息,如下图(bean shell脚本见步骤3)

3、添加察看结果树,查看接口是否跑通,导出文件的接口一般响应都是乱码,因为无法解析,如图

4、在导出文件接口的请求下增加BeanShell 后置处理程序,如图;

代码示例:
python
import java.io.*;
// 获取请求返回的数据,通过prev方法获取上一个请求的返回
byte[] result=prev.getResponseData();
//设置文件导出存放路径及保存的文件名
String file_name="C:/Users/Administrator/Desktop/导出文件.xlsx";
File file=new File(file_name);
FileOutputStream out=new FileOutputStream(file);
out.write(result);
out.close();
5、执行接口,查看结果,查看本地路径的文件;


最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!
