How to set the loop counter inside the loop inside jmeter?

I have a jmeter stream as follows:

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 elements = 2 and subItem = 10, my printout of loopCounter will be 0-19. I checked the checkbout "Posting counter independently for each user", but this does not affect, because it is the same thread. Is there a way to make the counter count 0 - 9, and then 0 - 9.

Thanks,

+6
source share
1 answer

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

In the sampler where numSubitem is installed (up to the 2nd cycle):

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

I used Beanshell Sampler for testing, you can use Beanshell post processor, for example.

In the instance instance:

enter image description here

Thus, the counter will be repeated in the same way as in your description.

+9
source

Source: https://habr.com/ru/post/912078/


All Articles