Jmeter——Reset Counter Counter Counter in Loop Controller

I recently used Jmeter to write an auxiliary test script, using multiple Loop Controllers and Counters.

The idea I had at the time was to implement three variable quantitative values ​​using loops; however, the number of times for the third variable value can only be determined based on the results obtained in the second loop, and each time the result will be different. Different situation. Based on the idea, I first wrote a linear script, and the implementation is as follows:

Insert image description here

But in practice, the third-level loop was not implemented as expected, so I thought of the Counter counter and added the Counter counter to the script. The implementation is as follows:

Insert image description here

The numbers in the picture illustrate: for 1 {for1}for1{for2}${for3}

${for1} is the Counter variable name in the first looper
${for2} is the Counter variable name in the second looper
${for3} is the Counter variable name in the third looper

As can be seen from the figure, ${for3} is cumulative, and the count will not be automatically reset when a cycle ends.

What I want to achieve is that the first obtained result in the second-level loop is 5 arrays, and the third-level loop is executed sequentially from index 0 to 4; the second obtained result in the second-level loop The result is 8 arrays, and the third level loop is executed sequentially from index 0 to 7.

But after this operation, the second time it will be executed directly from index 5, so part of the data will be lost, which is obviously not what I thought.

I tried a lot of mistakes along the way, but none of them could achieve the count reset function. Fortunately, one day I remembered the official document. This function is described in the document, as follows:

Insert image description here

The description in the document is very clear. You can use ${__jm__LC__idx} to achieve index starting from 0, where LC is the name of the controller.

Use the official website's documentation, add variables to the script, and run as follows:

Insert image description here

As can be seen from the picture, the fourth number of the third-level loop is what I want, and finally solved the problem in my mind.

The numbers in the figure illustrate: for 1 {for1}for1{for2}KaTeX parse error: Expected group after '_' at position 7: {for3}_̲{resetForNumber}

The first three numbers have been explained before. Here we only explain ${resetForNumber}. This variable is obtained through BeanShell Sampler, because the solution given by the official website is written in BeanShell Sampler. The code is as follows:

long i=0;
i = ${__jm__Loop Controller3__idx};
vars.put("resetForNumber",String.valueOf(i));

Although it is very simple to describe, it is indeed an obstacle encountered in the actual script implementation process. Fortunately, the problem has been solved.

Therefore, I have compiled this article in the hope that it will be helpful to friends who need it in the future.

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

Insert image description here

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!   

Guess you like

Origin blog.csdn.net/YLF123456789000/article/details/132901580