1. Introduction of JMeter components
1. Test plan
The test plan is usually used to rename the test project, and the thread group operation mode can also be configured when using a multi-threaded script to run
2. Thread group
Used to set the number of threads sending requests, the thread interval and the number of cycles
3. Configure components
1) Commonly used parameters for user configuration, such as: CSV Data Set Config, HTTP header manager, HTTP request default value, user-defined variables, etc. CSV Data Set Config for data parameterization
2) The HTTP information header manager user configures the request header parameters, the value of the token variable is taken from the return of the login interface, and other parameters refer to the browser F12 to view the request header data of the interface
3) The HTTP request default value is used to configure the interface default request parameters, configuration protocol, IP, port number, encoding, etc. All request parameters in the thread group are taken from this place
4) User-defined variables are used to set variable values
4. Pre-processor
Works before the request, used to modify the settings of the request
5. Timer
Used to set the delay time, commonly used fixed timer
6. Sampler
Send requests to the server, such as: HTTP Request Sampler, FTP Request Sample, TCP Request Sample, JDBC Request Sampler, etc. Each different type of request can send different types of requests to the server according to the set parameters, the most common one is HTTP Request Sampler
7. Post processor
Work after the request, used to obtain the data returned by the interface request, commonly used are JSON extractor, regular expression extractor, etc.
The following is the token return value of the login interface. In order to use this value in other interfaces, you need to add a post-processor to the login interface to obtain the token value, and then put it in the HTTP header manager
Select the regular expression extractor and set the name of the extracted access_token value to token
8. Affirmations
It is used to judge whether the result of the request response is as expected by the user, and generally intercept the return value of the interface
9. Listener
Responsible for collecting test results and determining the display methods of the results. Commonly used ones include viewing the result tree, aggregated reports, etc.
10. Logic controller
You can customize the behavior logic of JMeter sending requests, and it can be used in conjunction with Sampler to simulate complex request sequences
2. The scope and execution order of components
1. Scope
Configuration element: Affects all elements within its scope
Preprocessor: Executes before every sampler element in its scope
Timer: valid for every sampler within its range
Postprocessor: Executes after every sampler element in its scope
Assertion: Verify the results of each sampler element within its scope of action
Listener: Collect and present the information of each sampler element within its scope of action
2. Component execution sequence
Configuration element -> preprocessor -> timer -> sampler -> postprocessor -> assertion -> listener
Precautions:
Components such as preprocessors, postprocessors, and assertions can only act on samplers, so if there are no samplers in their scope, they will not be executed.
If there are multiple elements of the same type in the same scope, these elements will be executed sequentially according to their upper and lower order in the test plan