如何在jmeter中上传xls文件? [英] How can I upload xls file in jmeter?

查看:226
本文介绍了如何在jmeter中上传xls文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过我的应用程序中的xls文档通过批量上传过程招收了学生.您能否逐步说明通过Jmeter3.0中的xls文档上传学生详细信息的过程.

I have enroll students via bulk upload process through xls document in my application. Can you explain step by step process for upload student details through xls document in Jmeter3.0.

谢谢, 瓦伊拉穆图.

推荐答案

据我所知,JMeter不提供直接从xls上传的采样器.

As far as I know JMeter doesn't supply a sampler to upload from xls directly.

因此,我建议将输入文件转换为CSV并使用Config元素" CSV数据集配置".您可以找到很多步骤-互联网上的分步示例.

So I suggest to convert the input file in CSV and use the Config element "CSV Data Set Config". You can find a lot of step-by-step examples on internet.

无论如何,您可以使用 Apache Tika 和BeanShell(采样器,根据您的需求和测试计划进行预处理或后处理.

Anyway, you can read xls file using Apache Tika and BeanShell (sampler, pre or post processor depending on your needs and test plan).

下面是一个使用HTTP请求采样器读取xls文件(或更通用的二进制文件)的示例:

Here an example using HTTP request sampler to read the xls file (or more generic a binary file):

  • 下载tika-app.jar(JMeter 3.0使用版本1.12 tika -app-1.12.jar )
  • 将tika-app.jar文件复制到jmeter/lib目录.

  • Download tika-app.jar (JMeter 3.0 uses version 1.12 tika-app-1.12.jar )
  • Copy tika-app.jar file to jmeter/lib directory.

重新启动JMeter

Restart JMeter

打开JMeter测试计划并添加线程组

Open a JMeter test plan and add Thread group

添加"HTTP请求"采样器.

Add an "HTTP request" sampler.

  • 将字段"Protocol [http]"设置为文件".

  • Set the field "Protocol[http]" to "file".

将路径"字段设置为文件路径名(例如/mypath/Students.xlsx)

Set "Path" field to your file pathname (e.g. /mypath/Students.xlsx )

嵌套到"HTTP请求"中,添加"BeanShell PostProcessor"

Nested to "HTTP Request" add a "BeanShell PostProcessor"

  • 在脚本"区域中添加以下代码(在本示例中,假设您的xls文件具有工作表"Sheet1",三列,第一行作为标题);它读取文件并设置A1,B1,C1 jmeter变量:
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

try {

   InputStream in = new ByteArrayInputStream(data);
   Workbook wb = new XSSFWorkbook(in);
   in.close();
   Sheet sheet1 = wb.getSheet("Sheet1");
   Row row = sheet1.getRow(1);
   Cell a1 = row.getCell(0);
   Cell b1 = row.getCell(1);
   Cell c1 = row.getCell(2);
   vars.put("A1", a1.getStringCellValue());
   vars.put("B1", b1.getStringCellValue());
   vars.put("C1", c1.getStringCellValue());
}

catch (Throwable ex) {
   log.error("Failed ", ex);
}

  • 在"HTTP请求"采样器下方的同一级别,添加一个调试" 采样器和查看结果树"以查看变量(A1,B1,C1)
  • Below "HTTP Request" Sampler, at the same level, add a "Debug" Sampler and a "View Result Tree" to see the variables (A1, B1, C1)

这只是一个有关在JMeter中读取xls的示例,然后您可以决定从这里开始以获取有用的信息.

This is just an example about xls reading in JMeter, then you can decide to start from here to get something useful.

另请参见 tech-doing.com

这篇关于如何在jmeter中上传xls文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆