Jmeter如何在单个线程组或控制器中循环遍历不同属性的列表? [英] Jmeter how to loop through a list of different properties in a single thread group or controller?
问题描述
对于一组固定的控制器,如何通过不同的属性进行基本循环?循环控制器会运行设置组一定次数,但不会使用属性.
How to do a basic loop through different properties for a fixed set of controllers? Loop controller runs a set group a certain number of times, does not use properties though.
我可以做模块,并将值设置为属性以供多线程组使用,但是如何传递属性的下一次迭代,然后再次运行循环?
I can do modules, and set the values to properties for multi thread group usage, but how to pass the next iteration of the property, and run the loop again?
property x
do module (points to controllers)
next property
说我有一个44个字符的列表,我想在进行测试时在$ {name}中循环显示这些字符.我非常不希望为一个字符更改构建44套控制器.
Say I have a list of 44 characters, and I want to loop through those characters in a ${name} while I'm doing a test. I'd very much not like to build 44 sets of controllers for one character change.
请注意,我无法向计算机添加其他文件.它必须通过可用的控制器工作.我正在使用Jmeter 2.4 r961953
Please Note I cannot add extra files to my computer. It has to work via the stock available controllers. I'm using Jmeter 2.4 r961953
谢谢
推荐答案
我将详细介绍BeanShell方法.我的假设是,您希望在一个用户线程中执行此操作,如果这样,我的建议是:
I will elaborate slightly more about the BeanShell method. My assumption is that you'd like to do it within one User Thread, if so my proposal would be:
创建一个循环控制器.
- 逻辑控制器->回路控制器
在回路控制器内部添加以下条目:
- 配置元素->计数器
- 预处理器-> BeanShell预处理器
- 采样器-> 您的采样器
Counter 元素将用作索引,用于从数组中选择有效值,因此我们需要为 Counter 指定Reference Name
-假设它将是loopCounter
.
The Counter element will be used as an index that will be used to choose valid value from our array, hence we need to specify a Reference Name
for the Counter - let's say that it will be loopCounter
.
现在,我们必须切换到 BeanShell 预处理器并定义值数组.很棒的事情是,我们有vars
变量可用,它使我们可以CRUD访问场景中使用的变量:
Now we have to switch to BeanShell preprocessor and define the array of values. A great thing is that we have vars
variable available and it gives us CRUD access to variables used in the scenario:
String[] varArray = {"Value1", "Value2"};
idx = Integer.parseInt(vars.get("loopCounter"))-1;
vars.put("myVariable", varArray[idx]);
最后一步,在 mySampler 中,我们可以使用常规的JMeter方式使用变量:${myVariable}
And for the final step, inside mySampler we can use a variable in a regular JMeter way : ${myVariable}
JMeter API 可能会非常有帮助.
JMeter API can be very helpfull if you want a more sophisticated solution.
这篇关于Jmeter如何在单个线程组或控制器中循环遍历不同属性的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!