JMeter-如何从CSV中选择给定的行数以发送HTTP请求正文

时间:2019-03-07 11:59:23

标签: apache csv jmeter jmeter-plugins jmeter-5.0

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

假设我有10条记录的CSV文件test.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数据集配置,但它不提供此类功能。

1 个答案:

答案 0 :(得分:0)

这是一个非常自定义的用例,因此您必须使用__groovy() function

进行脚本编写

语法示例:

const newBuffer = bufferFromBufferString('<Buffer 54 68 69 73 20 69 73 20 61 20 62 75 66 66 65 72 20 65 78 61 6d 70 6c 65 2e>')
> newBuffer
<Buffer 54 68 69 73 20 69 73 20 61 20 62 75 66 66 65 72 20 65 78 61 6d 70 6c 65 2e>
> newBuffer.toString()
'This is a buffer example.'

演示:

enter image description here

有关JMeter中Groovy脚本的更多信息:Apache Groovy - Why and How You Should Use It