how to set counter of loop inside loop correctly inside jmeter?

妖精的绣舞 提交于 2019-12-01 15:54:35

问题


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

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.

Thanks,


回答1:


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:

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));

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

In Counter instance:

So counter will iterate as in your description.



来源:https://stackoverflow.com/questions/9949415/how-to-set-counter-of-loop-inside-loop-correctly-inside-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!