Preface:
1. The jmeter official website explains the logic controller as "logic controllers determine the order in which samplers are processed .". Logical controllers can control the execution sequence of samplers. It can be seen that the controller needs to be used together with the sampler, otherwise the controller has no meaning. All the samplervers placed under the controller are considered as a whole and will be executed together during execution.
2. Logic Controller in jmeter is divided into two categories:
A) control the logical execution sequence of nodes during the execution of the test plan, such as loop controller and if controller;
B) grouping the scripts in the test plan, facilitating jmeter to calculate the execution results and control the script runtime, such as throughput controller and Transaction Controller.
3. jmeter provides the following controllers:
1. Simple controller ):
Role: This is the simplest controller in jmeter. It allows us to organize our sampling tool and other logic controllers (grouping functions) to provide a block structure and control, it does not have any logic control or runtime functions.
2. Loop Controller ):
Purpose: specify the number of times the subnode runs. You can use a specific value (for example, set it to 5 times) or a variable.
1. Forever option: Check this option to keep repeating
2. If both the number of cycles in the thread group and the number of cycles in the loop controller are set, the number of times the subnode of the Loop Controller runs is multiplied by two values.
3. Once Only controller ):
Purpose: during the execution of the test plan, the subnode of the controller executes each thread only once. This controller is often used in login scenarios.
Note: once only controller is used as the subnode of loop controller. Once Only controller is executed in the first iteration of each loop.
4. foreach controller ):
Purpose: The foreach controller is generally used with User-Defined variables. It reads a series of related variables from User-Defined variables. The samplerger or controller under the controller is executed once or multiple times, and different variable values are read each time. For example:
Parameters:
- Input variable Prefix: prefix of input variables
- Output variable name: name of the output variable
- Start index for loop (exclusive): The index at the beginning of the loop (if not entered here, it starts from 1 by default. If no variable starts from 1, an error will be reported during execution)
- End index for loop (inclusive): index at the end of the loop
- Add "_" before number: whether to use "_" in the input variable name for interval.
User-Defined variables:
The variable name prefix is the name + underline defined by input variable prefix in the foreach controller (we checked the underline) + number.
Execution result:
After a total of three executions, the obtained variable value is assigned to the output variable outnmae, which can be called elsewhere through $ {outnmae.
V. Transaction Controller ):
Role: the Transaction Controller generates an additional sampler to count the time of the subnode of the controller.
Parameters:
- Generate parent sample: (if this parameter is selected, the result is displayed in a red box. Otherwise, the result is displayed in a blue box)
- Include duration of timer and pre-post processors in generated sample: If this item is selected, the time of the timer (timer) is counted. Otherwise, only the time of the sample is counted.
6. If controller ):
Purpose: Determine whether to execute the subnode under the node based on the value of the given expression. By default, the Javascript syntax is used for judgment (such as text in the red box ).
Parameters:
- Interpret condition as variable expression? : When this item is selected, it indicates whether the variable value is equal to the string true (Case Insensitive)
- Evaluate for all children: If this item is selected, the expression is calculated before each subnode is executed.
Example 1: Use the variable method for determination:
Example 2: Select interpret condition as variable expression?
7. Switch Controller ):
Purpose: The switch controller assigns a value to the value in the Controller to specify which sampler to run. There are two Assignment Methods:
- The first is a value. The subnode of the switch controller starts counting from 0 and determines which element to execute by referring to the value of the subnode.
- The second type is the name of the stator element, for example, the name of the sampler. If the specified name does not exist, no element is executed.
If the value is null, 1st subnode elements are executed by default.
Example:
1. The value selected by switch controller is login page.
2. Execution result:
VIII. throughput controller ):
Purpose: control the subnode execution times and load ratio allocation. There are also two ways:
- Total executions: set the number of running times
- Percent executions: Set the running ratio (1 ~ Between 100)
Example:
1. Set the thread group to loop for five times:
2. The subnode of throughput controller1 is executed three times:
3. Execute the subnode of throughput controller2 (40% * Number of thread group loops 5) = 2:
Execution result:
9. Random controller ):
Purpose: Randomly execute a subnode under it.
10. random order controller ):
Purpose: Randomly execute all subnodes under it.
Official website address:
Http://jmeter.apache.org/usermanual/component_reference.html#logic_controllers
Jmeter ---- Logic Controller)