JMeter CSV 数据集配置:如何在同一线程中移动变量? [英] JMeter CSV Dataset Config: how to move through variables in the same thread?

查看:38
本文介绍了JMeter CSV 数据集配置:如何在同一线程中移动变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个 CSV 数据集配置元素,它从这样的文件中读取:

I'm using a CSV dataset config element, which is reading from a file like this:

abd
sds
ase
sdd
ssd
cvv

基本上,它有一些 3 个字母的随机字符串.

Which, basically, has a number of 3 letter random string.

我将它们分配给一个名为 ${random_3} 的变量.

I'm assigning them to a variable called ${random_3}.

现在,我想在同一个线程中多次使用此列表中的值,但每次我都想移到下一个.例如,我希望第一个采样器使用 abd,第二个采样器使用 sds,然后是 ase,等等.但如果我只使用 ${random_3} 那么只有第一个 (abd) 被使用到它被引用的地方.有没有一种方法可以指定在线程内循环遍历 CSV 数据集中的值?

Now, I want to use values from this list multiple times within the same thread, but each time I want to move to next. For example, I want the first sampler to use abd, the 2nd to use sds, then ase, etc. But if I just use ${random_3} then only the first one (abd) is used wherever it's referred to. Is there a way I can specify to loop through the values from the CSV dataset within a thread?

推荐答案

CSV 数据集配置 可以很好地解决这个问题.所有的值都需要在文件的一列中,并按照描述将它们分配给变量.

CSV Data Set Config works fine for this. All of the values need to be in one column in the file and assign them to the variable as described.

创建一个线程组,该组为尽可能多的用户提供尽可能多的线程,只要您想遍历文件(即对 HTTP 请求执行操作).假设有 1 个用户,将线程数设置为 1,循环计数为 1.

Create a Thread Group that has as many threads for as many users as you want iterating over the file (i.e. acting on the HTTP Request). Assuming 1 user, set the number of threads to 1, loop count to 1.

在线程组内,您需要添加一个循环控制器或一个While控制器.您表示要遍历整个数据集.如果您添加循环控制器,您需要将循环计数设置为 6,因为您有 6 个值,每个值一个.或者(更容易处理整个文件)添加一个 While 控制器而不是循环控制器并将 ${random_3} 设置为 while 条件.

Inside the thread group you will need to add a Loop Controller or a While Controller. You indicated that you want to loop through the whole data set. If you add a loop controller you will want to set the Loop Count to 6, since you have 6 values, one for each value. Alternately (and easier for processing the whole file) add a While Controller instead of a Loop Controller and set ${random_3} as the while condition.

正确设置 CSV 数据集EOF 时回收EOF 时停止线程值很重要.如果您计划多次迭代文件,则必须将Recycle on EOF"设置为 True(即指示 jMeter 移回 CSV 文件的顶部).如果您使用的是循环控制器,请将在 EOF 上停止线程"设置为 False,如果您使用的是 while 控制器并希望在读取整个 csv 数据集后停止,则将其设置为 true.

It is important to set the CSV Data Set Recycle on EOF and Stop Thread on EOF values correctly. If you plan to iterate over the file more than once you must set "Recycle on EOF" to True (i.e. instruct jMeter to move back to the top of the CSV file). Set "Stop Thread on EOF" to False if you are using a loop controller, true if you are using a while controller and want to stop after reading the whole csv dataset.

将 CSV 数据集配置与 HTTP 请求一起添加为控制器的子项.使用您想使用的任何侦听器查看结果.

Add the CSV Data Set Config as a child of the controller along with the HTTP Request. View the results using any listener you want to use.

这篇关于JMeter CSV 数据集配置:如何在同一线程中移动变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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