如何在jmeter内部正确设置循环内循环的计数器? [英] how to set counter of loop inside loop correctly inside jmeter?

查看:49
本文介绍了如何在jmeter内部正确设置循环内循环的计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 jmeter 流程​​:

I have jmeter flow like this:

ThreadGroup
--Sampler to get the number of items and store to vars("numItem",XYZ)
--LoopController on $numItem
-----Sampler to get number of subItem and store to vars("numSubitem", ABC)
-----LoopController on $numSubitem
-----LoopCounter
-----Sampler: print out the current counter from loopCounter

例如,item 的数量 = 2 和 subItem = 10,我的 loopCounter 打印输出将是 0 - 19.我已经检查了每个用户独立跟踪计数器"的结账,但它不会影响,因为这是相同的线程.有没有办法让计数器先计数 0 - 9,然后再计数 0 - 9.

For example, the number of item = 2 and subItem = 10, my loopCounter print out will be 0 - 19. I have checked the checkbout "Track counter independently for each user" but it doesn't affect because this is the same thread. Is there a way to make the counter count 0 - 9 and then 0 - 9.

谢谢,

推荐答案

在您的示例中,您可以定义额外的 var maxCount = subItem - 1 并将其设置为Counter"的Maximum"字段的值" 实例,如下图:

In your example you can define additional var maxCount = subItem - 1 and set it as value of "Maximum" field for "Counter" instance, as shown below:

在设置了 numSubitem 的采样器中(在第二次循环之前):

In sampler where numSubitem is set (before 2nd loop):

int numSubitem = 10;
int maxCounter = numSubitem - 1;
vars.put("numSubitem",Integer.toString(numSubitem));
vars.put("maxCounter",Integer.toString(maxCounter));

我使用 Beanshell Sampler 进行测试,您可以使用 Beanshell Postprocessor,例如

I've used Beanshell Sampler for test, you can use Beanshell Postprocessor, e.g.

在计数器实例中:

因此计数器将按照您的描述进行迭代.

So counter will iterate as in your description.

这篇关于如何在jmeter内部正确设置循环内循环的计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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