1

我的测试用例是在每个请求中按顺序将给定数量的行从 CSV 文件发送到 HTTP 请求正文。我尝试使用CSV 数据集配置,但它允许每个请求只读单行。是否可以使用 JMeter 从给定批次中的 CSV 读取数据(例如,每个请求正文中 5 个简单的逗号分隔纯文本行)?

假设我有test.csv10 条记录的 CSV 文件。

no,name,email
1,test,test@test.com
2,test,test@test.com
3,test,test@test.com
4,test,test@test.com
5,test,test@test.com
6,test,test@test.com
7,test,test@test.com
8,test,test@test.com
9,test,test@test.com
10,test,test@test.com

现在我想将此 CSV 中的 2 行(简单的逗号分隔的纯文本行)发送到 JMeter HTTP 请求正文。可以使用 JMeter 吗?

我尝试使用 CSV Data Set Config,但它没有提供这样的功能。

4

2 回答 2

0

您可以使用__CSVReadnext函数作为第二个参数获取超过 1 行:

例如,您可以如下设置一些变量:

  • COL1a ${__CSVRead(random.txt,0)}
  • COL2a ${__CSVRead(random.txt,1)}${__CSVRead(random.txt,next)}
  • COL1b ${__CSVRead(random.txt,0)}
  • COL2b ${__CSVRead(random.txt,1)}${__CSVRead(random.txt,next)}
于 2021-11-25T10:36:21.300 回答
-1

这是一个非常自定义的用例,因此您必须使用__groovy() 函数编写脚本

示例语法:

${__groovy(new File('test.csv').readLines().subList(1\,3).join('\,'),)}

演示:

在此处输入图像描述

有关 JMeter 中 Groovy 脚本的更多信息:Apache Groovy - 为什么以及如何使用它

于 2019-03-07T12:36:03.313 回答