Jmeter (9) - from entry to mastery - JMeter Logic Controller - Part 1 (detailed tutorial)

content

1 Introduction

2. Classification of logic controllers

3. Preview the logic controller family

4. Detailed explanation of common logic controllers

5. Summary


1 Introduction

The explanation of the logic controller on Jmeter's official website is: "Logic Controllers determine the order in which Samplers are processed.".

Meaning, the logic controller can control the execution order of the samplers. It can be seen that the controller needs to be used with the sampler, otherwise the controller is meaningless. All samplers placed under the controller will be treated as a whole and will be executed together when executed.

The JMeter logic controller can control the execution logic of the element. In addition to the one-time controller, other types of logic controllers can be nested.

2. Classification of logic controllers

Logic Controllers in JMeter are divided into two categories:

(1) Control the logical execution sequence of nodes during the execution of the test plan, such as: Loop Controller, If Controller, etc.; (2) Group the scripts in the test plan to facilitate JMeter to count the execution results and control the runtime of the scripts, etc. Such as: Throughput Controller, Transaction Controller.

3. Preview the logic controller family

First, let's take a look at the logic controller of JMeter, the path: thread group (user) -> add -> logic controller (Logic Controller); we can clearly see that there are 17 logic controllers in JMeter5, as shown in the following figure :

If you can't see the above picture clearly, Brother Hong summed up a mind map, about the type of logic controller of JMeter5, as shown in the following figure:

Through the above understanding, we have a general understanding and understanding of the logic controller. Below, Brother Hong will share and explain some logic controllers that are usually used in work to small partners or children's shoes.

4. Detailed explanation of common logic controllers

  In this section, Brother Hong will explain the commonly used logic controllers in detail from top to bottom . Due to time constraints, Brother Hong divided this part into three parts: upper, middle and lower.

4.1if Controller

In actual work, when using Jmeter for interface testing or performance testing, it is sometimes necessary to perform different operations according to different conditions. To solve this problem, Jmeter provides an IF controller. As the name implies, the IF controller implements the function of IF in the code, and determines whether to perform the corresponding operation by judging the True/False of the expression. It is judged by the condition that the node below executes or not.

1. Let's take a look at what this if Controller looks like. Path: Thread Group > Add > Logic Controller > If (if) Controller , as shown in the following figure:

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty.

Expression (must evaluate to true or false) : Expression (value must be true or false), that is, the conditional value entered in the right text box must be true or false, (by default)

Interpret Condition as Variable Expression?: The default tick option, interprets the condition as a variable expression (need to use __jexl3 or __groovy expression)

Evaluate for all children?: The condition is applied to each sub-item (for specific understanding, Brother Hong will give an example in the actual combat chapter) to determine whether the condition is for all children. By default, it is not checked, and it is only judged once at the entrance of the if Controller.

Note: Knock on the blackboard! ! ! Knock on the head! ! !

1. The yellow exclamation mark on the text box is to remind you that it is recommended to use __jexl3 or __groovy expressions to improve performance, which is the default method.

2. The if controller can only act on the sub-items under it

4.1.1 Default usage

1. The default usage is to use the __jexl3 or __groovy expression. If the controller has a sampler that accesses the homepage of Beijing Hongge's blog garden, the sampler will be executed only when the if condition is satisfied. By default, the condition 'Beijing Hongge'=='Beijing Hongge' is put into the __jexl3 expression. As shown below:

2. If you don't know how to use the expression, you can use the function assistant of Jmeter, the function assistant icon > select _jexl3 > enter 'Beijing Hongge' == 'Beijing Hongge' in the value input box > click 'Generate' > All Select Ctrl+C to copy > Ctrl+V to paste into the expression as shown below:

3. After configuration, run JMeter, select HTML, and view the result tree, as shown in the following figure:

 4.1.2 Direct input conditions

1. For direct input, just remove the check box in front of " Interpret Condition as Variable Expression? " and directly input the condition: 'Beijing Hongge'=='Beijing Hongge' . A sampler that visits the home page of Beijing Hongge's blog garden will be executed. As shown below:

2. After configuration, run JMeter, select HTML, and view the result tree, as shown in the following figure:

4.13 Using variables in conditions

In many test scenarios in our daily work, we need to make conditional judgments based on user variables or the return value of the previous sampler to decide whether to execute a certain sampler.

1. First, we add a user variable: Beijing Hongge. Condition: When the value of Beijing Hongge is Hongge , the sampler that accesses the homepage of Beijing Hongge Blog Park is executed. As shown below:

User variables and configuration, as shown in the following figure:

2. IF Controller and configuration, or you can use the expression: Missing open brace for subscript{Beijing Hongge}'=='Hongge' ,)}. As shown below:

 4.1.4 Usage of Evaluate for all children?

1. Brother Hong explained and shared how to use variables in conditions in the above section. We assume a test scenario: if the value of the variable is changed after the sampler under the if controller is executed, the Will subsequent samplers continue to be executed? Follow Brother Hong to take a look at the following columns:

2. Change the value of the variable "Beijing Hongge" to " Beijing Hongge ", as shown in the following figure:

3. Logical analysis of JMeter execution process:

(1) There are 3 samplers under the if controller, the initial value of the variable Beijing Hongge is Hongge, and the condition of the if controller is: {__jexl3("

(2) If the conditions are met at the beginning of execution, then it stands to reason that the three samplers of visiting the blog garden home page , visiting Beijing Hongge , and visiting Hongge’s articles should be executed.

(3) However, after visiting the homepage of Beijing Hongge's blog garden , the value of Beijing Hongge is changed to Beijing Hongge , which can no longer satisfy the "${Beijing Hongge}"=="Hongge" condition.

(4) So visit Hong Ge's JMeter series of articles , this sampler will not be executed.

4. Run JMeter, view the result tree, and compare the results of the operation with those analyzed by Hongge, as shown in the following figure:

5. If at this time, remove the check of Evaluate for all children?, what will happen, you can try it yourself. Remember to click "Save" after making changes. Below is the execution result of Brother Hong, as shown in the following figure:

In addition, if the string must use quotation marks, the variables are considered to be in the form of strings, such as: Missing open brace for subscript

4.2Transaction Controller

  Transaction response time is the main indicator for us to measure business performance. The transaction controller can accumulate the execution time of samplers under other nodes for easy statistics. At the same time, the execution time of each sampler is counted. If there are multiple samplers under the transaction controller, only when all the samplers run successfully, the transaction defined by the entire transaction controller is considered successful. It is used to organize a specific part of the Test Plan into a Transaction. The role of the Transaction in JMeter is to count the response time, throughput, etc. of the Transaction. For example, a user operation may require multiple Samplers to simulate. In this case, the Transaction Controller can be used to obtain more accurate performance indicators of the user operation, such as response time. This time includes all processing time within the scope of this controller, not just the sampler's.

This is very useful. We mentioned the concept of transaction earlier. Sometimes we don't care about the response time of a single request, but the overall response time of a group of related requests. How to count it? It is necessary to use the concept of transaction to put this group of requests under a transaction controller.

1. Let's take a look at what this Transaction Controller looks like. Path: Thread Group > Add > Logic Controller > Transaction Controller , as shown in the following figure:

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

generate parent sample: choose whether to generate a parent sampler;

include duration of timer and pre-post processors in generated samle: whether to include a timer, the choice will add a delay before and after the sampler. (Brother Hong recommends that you do not check, otherwise the statistics will be more troublesome, and you need to deduct the delay)

4.2.1Generate parent sample usage

1. Brother Hong enumerates a test scenario: We need to know the response time of a single request for the two requests of visiting the homepage of the blog park and the home page of Beijing Hongge's blog park, so let's take a look at the following example.

(1) For a single request, then do not check generate parent sample, as shown in the following figure:

2. Run JMeter to view the response time of a single request in the aggregated report, as shown in the following figure:

1. Brother Hong lists a test scenario: We need to understand the response time of the two requests to visit the homepage of the blog park and the home page of Beijing Hongge's blog park as a set of requests, so let's take a look at the following example.

(1) For a group of requests, then check generate parent sample, as shown in the following figure:

2. Run JMeter to view the response time of a group of requests in the aggregated report, as shown in the following figure:

4.3Loop Controller

The loop controller can control the execution times of the element under its node, which can be a specific number or a variable.

1. Let's first take a look at what this Loop Controller looks like. It loops once by default. Path: Thread Group > Add > Logic Controller > Loop Controller , as shown in the following figure:

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Forever: Checking this item means that the cycle will continue.

Note: Knock on the blackboard, knock on the skull! ! !

If the number of loops of the thread group and the number of loops of the loop controller are set at the same time, the number of times the child node of the loop controller runs is the result of multiplying the two values.

4.3.1 Difference between Thread Group and Loop Controller

1. Now Hongge prepares two requests, set up a thread group with 1 thread and 5 loops, and there is a request below: visit the home page of Beijing Hongge's blog park, a Loop Controller (set 2 loops), and there is a request below: access Blog Garden Home

(1) Thread group, as shown in the following figure:

(2) Loop controller, as shown in the following figure:

2. Run JMeter and view the result tree. In order to see the result clearly, Brother Hong deliberately configures the first request to fail; as shown in the following figure:

From the above results it can be seen that:

(1) If the number of loops of the thread group and the number of loops of the loop controller are set at the same time, the number of times the child nodes of the loop controller run is the result of multiplying the two values.

(2) The running order is: execute the loop in the thread group first, and then execute the loop in the loop controller.

4.4While Controller

The While Condition Controller, the elements under its node will run until the While Condition is false.

1. Let's first take a look at what this While Controller looks like. It loops once by default. Path: Thread Group > Add > Logic Controller > While Controller , as shown below:

2. The key parameters are described as follows:

Name: name, can be set at will, or even empty;

Comments: Comments, can be set at will, can be empty;

Condition: accepts variable expressions and variables. When the condition is Flase, the While loop will be jumped out, otherwise the components under the While controller will be executed all the time.

3. The While controller provides three constants

(1) Blank: stop when the last sampler in the loop fails

(2) LAST: When there is a sampler failure before the cycle, do not enter the cycle

(3) Other: When the judgment condition is false, stop the loop

4.4.1Blank

1. Don't fill in (blank): When the execution of the last sample under the While controller fails, it will jump out of the loop, as shown in the following figure:

2. Run JMeter and view the result tree, (you can drag the last failed sampler with the mouse, and when you move to the first or second position, after running JMeter, you will find that it is running all the time); as shown in the following figure :

4.4.2LAST

LAST : Jump out of the loop when the last sample under the While controller fails to execute. If the previous sample of the While controller fails to execute, it will not enter the While loop, that is, the sample under the While controller will not be executed.

1. The sampler tree is still in the position and order above. This time we fill in the While controller expression: LAST, as shown in the following figure:

2. Run JMeter and view the result tree, (you can drag the last failed sampler with the mouse, and when you move to the first or second position, after running JMeter, you will find that it is running all the time); carefully you can It is found that the loop only runs once, and the result of not filling is the same as shown in the following figure:

3. But when LAST is input, there will also be a result, that is: if the previous example of the While controller fails to execute, it will not enter the While controller

Add two samplers in front of the While controller: sampler 1 accesses Baidu , sampler 2 accesses Beijing Hongge. Make sampler 2 access Beijing Hongge . The execution fails. Sampler 2 must be in front of the While controller and fails to execute. As shown below:

4. Run JMeter, check the result tree, and find that the sampler 1 and sampler 2 are executed, but they do not enter the While controller, as shown in the following figure:

4.4.3Otherwise

Custom condition: a function/variable/attribute expression with a value of True or False; similar to the IF controller explained earlier, Brother Hong will take the example of a cat and a tiger here.

1. User-defined variable, variable name: Beijing Hongge, variable value: true, as shown in the following figure:

2. While controller configuration, get the value of the variable: ${Beijing Hongge}, fill in the place of the expression, as shown in the following figure:

3. Logical analysis of JMeter execution process:

(1) There is a user-defined variable under the Beijing Hongge user (thread group), the value of the variable Beijing Hongge is true , and the condition of the While controller is: The value obtained by ${Beijing Hongge} is always true .

(2) Therefore, once the conditions are always met, it stands to reason that it should be executed all the time. Visit the homepage of the blog garden , visit the homepage of Beijing Hongge's blog garden , and visit the three samplers of Hongge's JMeter series articles .

4. Run JMeter, check the result tree, (after running JMeter, you will find that it is running all the time), and compare it to see if it is highly consistent with Brother Hong's analysis; as shown in the following figure:

5. Summary

Well, today's last article about logic controllers is here. This article mainly introduces the IF controller , the Transaction Controller , the Loop Controller and the While controller .

Your affirmation is the driving force for my progress. If you feel good, please encourage it! Remember to click on the wave and recommend it, don't forget it! ! !

Don't forget to click recommend and leave traces of your visit

Guess you like

Origin blog.csdn.net/ZangKang1/article/details/124148394