我记录了一个上传excel的场景,在下一个后续请求中,excel中的这些记录作为参数传递。
但是假设我需要更改 excel,该请求将如何采用新值?
由于大量值,参数化似乎不是答案。
请帮忙。
我记录了一个上传excel的场景,在下一个后续请求中,excel中的这些记录作为参数传递。
但是假设我需要更改 excel,该请求将如何采用新值?
由于大量值,参数化似乎不是答案。
请帮忙。
如果您需要从 Excel 文件中提取一些值并将它们添加为 HTTP 请求参数,您可以使用以下方法。
在“脚本”中是开发代码,它读取 Excel 文件并从中添加值作为 HTTP 请求参数。下面的代码示例从 testfile.xlsx 文件的 A1 和 B1 单元格中提取值,并将它们作为“foo”和“bar”HTTP 请求参数发送。
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
FileInputStream excelFile = new FileInputStream(new File("/path/to/excel/testfile.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(excelFile);
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
Cell a1 = row.getCell(0);
String a1Value = a1.getStringCellValue();
Cell a2 = row.getCell(1);
String a2Value = a2.getStringCellValue();
excelFile.close();
sampler.addArgument("foo",a1Value);
sampler.addArgument("bar",a2Value);
参考: