Jmeter Web platform interface test script 3-file download test (use BeanShell to save the file locally)

step:

  1. Open Fiddler packet capture function
  2. Download the file in the platform to be tested
  3. View download-related data captured by Fiddler, and view the incoming parameters
  4. Create a Jmeter HTTP request and pass in the above parameters.
  5. Create a regular extractor to get the file name in the returned data
  6. Create a BeanShell post processor and save the file locally with the string extracted from the regularization as the file name

Insert picture description here
Insert picture description here

File download HTTP request:
Insert picture description hereObserve that the name of the downloaded file is in the return header:
Insert picture description here

Use regular to extract the current file name:
Insert picture description here
use BeanShell to save the returned body content to the local:
Insert picture description here
BeanShell code

import java.io.*;

 

//获取上个请求的返回数据

byte[] result = prev.getResponseData();

String f = vars.get("filename_01"); 
String file_name = "D:/a/".concat(f); 
File file = new File(file_name);

FileOutputStream out = new FileOutputStream(file);

out.write(result);

out.close();

Guess you like

Origin blog.csdn.net/KathyLJQ/article/details/110646445