Today, let's share Jmeter Medium 2 Loop controller ,ForEach Controller and Loop Controller, There are still some differences in use . # ForEach Controller ## ForEach Controller Introduction ForEach Controller It can be understood as an iterator (iterator), It is to traverse all the data that meet the current conditions , Can be used for Jmeter Indexation in instruction code . Let's look directly at the picture , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105155135057-670411253.png) As shown above , Namely ForEach Controller Configuration interface of , The interface has the following arguments , Explain one by one : - Name: Controller name , It can be filled in according to the user's needs , You can leave it blank - Comments: Users can fill in the form of , You can leave it blank - Input variable prefix: Input variable number first , Source :① Users can use the “ User defined variables ” Define a set of variables in , The loop controller can get the corresponding value of the variable from it , And then as a loop condition ;② The user can use the extracted argument as the loop condition - Start index for loop(exclusive): Start circling the fields , Loop variable subscript starting point ( It doesn't contain ) - End index for loop(inclusive): Loop variable subscript end point ( contain ) - Output variable name: Output variable name , The name of the variable generated by the loop controller , The name of the argument filled in during the reference is consistent with the name of the output variable - Add "\_"before number?: Underline the number “\_”, Whether to add... To the beginning of a number “_” As a separator ## ForEach Controller Use Let's look directly at the case ,ForEach Controller How to use . As mentioned above , The source of the variable , Taken from 2 In this case , Let's get to know one by one . But before the operation , Each has to have Jmeter Environment , Environment configuration can refer to the previous blog . ### User defined variables A user-defined variable is one of the configuration components , Definable arguments , The following interface can be used directly , It's also a way of indexation . The new entry to the component is shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105160524493-290418344.png) Let's define a set of data , I'll take my own blog as an example , After configuring arguments , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105160628937-216297142.png) We can see that , Variable names have rules to follow , It's all about wd_number The beginning . Maybe there's a question , Why do you set it like this , Keep looking down , You'll soon know what it does . When we configure the argument source , This needs to be done in ForEach Controller Configure the corresponding data , Keep up with the rhythm . We were before ForEach Controller It is learned in the introduction that , One argument is `Input variable prefix Input variable number first `, The input here is `wd_number`. Because we're in the components of user-defined variables , A set of configuration data starts with this . `Start index for loop(exclusive)` and `End index for loop(inclusive)` You can not configure , Non required information . If configured , It should be noted that , The starting bit is not included , It will be clear from the screenshot of the case . `Output variable name` Output variable , This argument is the reference name used for subsequent arguments , For example, we usually use the regular extractor , Also need to define a variable , The same meaning . `Add "\_"before number` This is to see what the custom variable names are , There's... Between variables `_`, You need to check , If not , Don't check it . The configuration results are as follows : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105162645012-163140127.png) We'll use `outwd` Variable reference to the corresponding interface argument , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105162430710-898320282.png) So far , The configuration steps have been completed , We're going to execute the instruction code directly , Take a look at the execution results , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105162719496-735765156.png) It can be seen from the results of the implementation that , We don't set the number of loops , But why is 5 Time , Because the variables we set are only 5 One , And the variable request interface is replaced in turn , This is not the ordinary indexation , Is it simple . The result just now , We don't configure the start stop position of the loop , Now we configure the upper start stop position , The configuration is as follows : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105163013939-336350520.png) Execute the instruction code again , Let's see what the result is , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105163119921-1161074285.png) From the results of the implementation in the above figure, we can clearly see its role , The starting position is ` It doesn't contain ` Of , The ending position is ` contain `, Configure to 1 and 3, So the execution result is to take 2 and 3 To request the interface . ### Extract arguments Take Blog as an example , Everyone's blog has three lists , Reading the leaderboard 、 The latest comments 、 Recommended rankings , It's just right for this demo. You can look at the information , It's all one a Label , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105164626453-721644042.png) By means of user-defined variables , There must be ideas , How to extract arguments . We use regularization , Will 15 Data extraction , And configure the corresponding arguments to ForEach Controller that will do . Let's start with regular matching , The knowledge of regularity is supplemented by itself , You can also refer to my previous blog posts , I won't repeat it today . We observe the data to be extracted , There are rules to follow , New regular extractor , And configure it as follows : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105165156302-387176606.png) What needs to be noted here is ,`Match No.`, We configure it here as `-1`, Because you need all the values that meet the criteria : - Configure to 0, Random values are random values ; - Configure as a positive integer , Indicates the number of matched data ; - Configure to -1, It means to get all the data matched . After the regular configuration , Can execute instruction code , Let's see if we've got the data properly , Debugging is also part of the job of writing instructions . Let's configure ForEach Controller, As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105165903529-494697128.png) Then the output variable is referred to the corresponding interface argument , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105170005225-1934631544.png) Let's execute the instruction code , Look at the overall effect , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105170146815-1277517650.png) As shown above , Separately requested 15 Subinterface , Is it convenient to use , Here we are , Is it possible to use it , That's how easy indexation is . # Loop Controller ## Loop Controller Introduction Loop Controller, Function expansion suite is not strong , Can only be configured as infinite loops and specific number of loops , It is mainly used to test the repeated calls of the interface . Let's get to know , As shown below : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105171121728-8048202.png) According to the picture above , To understand the argument configuration : - Loop Controller: Component name - Name: Controller name - Comments: Note - Loop Count: Set the execution times ,Infinite Check to indicate permanent execution ## Loop Controller Use Loop Controller It's easy to use , We can see clearly from the configuration interface , It's nothing more than configuring the number of loops , Or all the time in infinite circles . ### Specify the number of loops Let's look at the effect intuitively through the case , The number of times is set for us 2, And execute the instruction code , The execution results are as follows : ![](https://img2020.cnblogs.com/blog/1242227/202011/1242227-20201105172144047-1945240357.png) We can see from the above figure that , The number of loops is 2, Every interface calls 2 Time . For example, some businesses , The back-end interface has repeated call verification , It can be verified in this way . ### Infinite loops If it is configured as infinite loop , As the name suggests , That must have been executing the instruction code , Unless it's stopped manually , The script stops executing . Okay , Today's 2 The loop controller is introduced here , To sum up , If it's used for indexation , You will definitely use ForEach Controller.2 Kind of controller , Each has its own function , each takes what he needs , Hope to have something for the bloggers in need
版权声明
本文为[itread01]所创,转载请带上原文链接,感谢