我正在使用Jmeter和JSON进行REST API的功能测试。我有文件上传工作,但我似乎无法将文件下载到jmeter工作。我正在保存这篇文章中提到的回复:JMeter - File upload and file download scenario
当我这样做时,我越来越接近但不完全正是我所需要的。这是我得到的例子:
--0rVAdzesdQq7VrwJaRoYGm_UHdMD5nhi9_5w4u
Content-Disposition: form-data; name="api-test"; filename="LIBFILE1.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Library File for Automated Smoke Test
This file is used to test file library upload for automated smoke tests.
--0rVAdzesdQq7VrwJaRoYGm_UHdMD5nhi9_5w4u--
如何才能将下载保存为仅保存文件内容?在这个例子中,它应该只是:
Library File for Automated Smoke Test
This file is used to test file library upload for automated smoke tests.
这是一个简单的文本文件。我还想下载我正在上传的其他格式,包括jpg,png,docx,pdf,但如果它有这个额外的数据,那就不对了。我想一旦我得到一个简单的文本文件,它将帮助我获得更难的文件类型。
答案 0 :(得分:1)
嗯,Save Responses to a file侦听器会将您可以观察到的数据存储在View Results Tree侦听器的“响应数据”选项卡中。如果您将这些Content-Type
,Content-Disposition
等标题视为响应数据 - 很可能您的上传不成功,因为您不应该以这种方式获取标题。
我建议仔细检查通过浏览器或Postman工具执行的同一请求是否返回相同的响应并修复您的JMeter脚本以防出现差异。
有关如何使用JMeter正确模拟文件操作的详细信息,请参阅Performance Testing: Upload and Download Scenarios with Apache JMeter文章。
将响应数据保存到文件中的另一种方法是使用JSR223 Listener,如果您在语言下拉列表中选择“groovy”,则应该能够使用以下简单脚本保存响应:
new File("/path/to/your/file.txt").setBytes(prev.getResponseData())