Jmeter (sixteen) - from entry to proficient - JMeter preprocessor (detailed tutorial)

content

1 Introduction

2. Preview the preprocessor

3. Detailed explanation of common preprocessors

4. Summary


1 Introduction

  The preprocessor is to perform some operations before issuing a "sampler request". If a preprocessor is attached to a sampler element, it will execute before that sampler element runs. Preprocessors are most commonly used to modify the settings of a sampler request before it runs, or to update variables not extracted from the response text. The preprocessor is mainly used to process some preparatory work before the request, such as parameter setting, environment variable setting and so on.

2. Preview the preprocessor

  First, let's take a look at JMeter's preprocessor, the path: thread group (user) -> add -> preprocessor (); we can clearly see that there are 8 preprocessors in JMeter5 (excluding jp The preprocessor at the beginning of @gc, this is a plug-in installed by Brother Hong), 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 preprocessor of JMeter5, as shown in the following figure:

 

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

3. Detailed explanation of common preprocessors

In this section, Brother Hong will explain the commonly used preprocessors in detail from top to bottom .

3.1JSR223 PreProcessor

The JSR223 preprocessor is used to process the collector before the sampler is started.

1. Let's take a look at what this JSR223 PreProcessor looks like. Path: Thread Group > Add > Preprocessor > JSR223 Preprocessor , 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;

Language: language, the language selected for the development script, the JSR223 language used, can be selected according to needs;

Parameters: parameters, parameters passed to the script;

File Name: file name, locally developed script file (will overwrite the script written in JMeter);

Script compilation caching: Store compiled scripts, checked by default;

Script: To run the script. Scripting area.

3.1.1 Examples

The usage is similar to the Beanshell sampler, you can refer to: Jmeter (fifteen) - from entry to master - JMeter import custom Jar package This article. The specific usage is as follows:

1. Create a new test plan and add the JSR223 preprocessor under the thread group, as shown in the following figure:

 

2. Then add the debug sampler, as shown below:

 

3. Reference script code:

import com.bjhg.test.BeanShellJMeter;


BeanShellJMeter bs = new BeanShellJMeter("宏哥","北京");


vars.put("username",bs.getUserName());

4. After the configuration is complete, click "Save", run JMeter, and view the table results, as shown in the following figure:

 

3.2 User Parameters

User parameters are used to make several sets of parameters for each thread of the thread group to use. If the number of threads is more than the number of user parameter groups, the extra threads will call the parameter groups in turn from the first set of user parameters; Different thread groups (users) use different variable values.

1. Let's take a look at what this user parameter looks like. Path: Thread Group > Add > Preprocessor > User Parameters , 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;

Update Once Per Iteration: identifies whether to update the element once per iteration;

3.2.1 Examples

1. Create a new test plan and add user parameters under the thread group, as shown in the following figure:

 

2. Then set the number of threads to 3, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results, as shown in the following figure:

 

3.3 HTML Link Parser

HTML link parser, used to parse links and forms from the html page returned by the previous sampler according to the rules, and then match and modify according to the rules in the sampler where the processor is located, and then the sampler will execute;

1. Let's take a look at what this HTML link parser looks like. Path: Thread Group > Add > Preprocessor > HTML Link Parser , as shown in the following figure:

 

3.3.1 Examples

1. Create a new test plan, add 1 one-time controller under the thread group, add 1 HTTP header manager and 2 samplers to search and click the link under the one-time controller, as shown in the following figure :

(1) HTTP header manager

 

(2) Du Niang search (this sampler is a search request and returns an HTML page)

 

(3) Click on the link (this sampler adds an HTML link parser, the parser will match the HTML page returned by the sampler according to each regular expression in the sampler and send the sampler)

 

2. Then click on the link to add the HTML link parser, as shown in the following figure:

 

3. After the configuration is complete, click "Save", run JMeter, and view the table results (), as shown in the following figure:

(1) Du Niang search results

 

(2) Click the link result

 

3.4 HTTP URL Rewrite Modifiers

HTTP URL rewrite modifier. This processor is similar to HTTP Link Parser, but it is dedicated to http requests that use url rewriting to store sessionId instead of cookies. Adding this modifier at the thread group level applies to all samples. If it is a single Adding a sample only applies to that sample. As the name suggests, it helps us redirect URL requests; rewrite URLs to store session ids. We know that the session between the browser and the server is generally managed by a cookie, which is the HTTP Cookie Manager in JMeter, but there is another way of maintaining a session in practice. For example, the system only allows users who have successfully logged in to access the system. When the user logs in successfully, a SessionID (or JsessionId) is returned to the user, and subsequent accesses need to verify this SessionID. If the subsequent requests are submitted in the form of Get, then the SessionID needs to be attached to the URL link, and every Get request is the same. This kind of repetitive work can obviously be done with one operation. In JMeter This action is the HTTP URL rewrite modifier.

Why use URL address rewriting? Because of the security settings of some browsers, the session is disabled. The principle of the session is to save the session ID in the client's cookie. Therefore, if the cookie function is disabled at this time, all functions using session will be invalid. If the url address rewriting technology is used, the server will encode the session and write it after the url address as a parameter to pass. This not only improves the customer The security of the terminal is also avoided, and the risk of the function being shielded is avoided.

1. Let's first take a look at what this HTTP URL rewrite modifier looks like. Path: Thread Group > Add > Preprocessor > HTTP URL Rewrite Modifier , 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;

Session Argument Name: Session parameter name, used to search for sessionId, other samples can also call the obtained sessionId through this parameter;

Path Extension: Path extension, if a semicolon is added to the url as a division, check this option;

Do not use equals in path extension: used for url to separate key and value types without equals sign;

Do not use questionmark in path extension: for use without ? type;

Cache Session Id?: If this option is checked, the sessionId obtained from the mounted sample will be stored for use by other samples later;

URL Encode: whether to use url encoding;

3.4.1 Example HTTP URL Rewriting Modifier Principle

 

3.5JDBC PreProcessor

The database preprocessor is used to query the database and get some values ​​before the sample starts; the jdbc preprocessor is the same as the sampler's JDBC Request. You can refer to this article

1. Let's take a look at what this JDBC PreProcessor looks like. Path: Thread Group > Add > Preprocessor > JDBC Preprocessor , 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;

Variable Name of Pool declared in JDBC Connection Configuration: The name of the connection pool, which must be the same as the Variable Name in the JDBC connection configuration (this preprocessor requires a JDBC Connection Configuration, which is in the configuration element);

Query Type: database query type, you can choose it according to your needs;

Query: database statement input box, enter as needed, be careful not to add ";" at the end;

Parameter values: parameter name, if there is "?" in the Query statement, fill in the value here, you can use the calling parameter method;

Parameter types: parameter type, corresponding to Parameter values, set the parameter type, the same as the sql field type;

Variable names: Set this to get all the values ​​of the fixed column;

Result variable name: Set a name at will, then this name will be used as a parameter and correspond to the content of Query; you can use the method of parameter calling to get the value corresponding to the name of this setting;

Query timeout(s): timeout time;

Handle ResultSet: There are four options, the way the result is saved;

3.6RegEx User Parameters

Regular expression, use regular expression to specify dynamic values ​​for HTTP parameters extracted from another HTTP request, used with regular expression extractor. I haven't found a good example for the time being, and I think of adding it later. .

1. Let's take a look at what this JSR223 PreProcessor looks like. Path: Thread Group > Add > Preprocessor > JSR223 Preprocessor , 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;

Regular Expression Reference Name: The reference name in the called regular expression extractor;

Parameter names regexp group number: the group number of the regular expression used to extract parameter names;

Parameter values ​​regex group number: The group number of the regular expression used to extract parameter values.

3.7Sample Timeout

The timeout timer is used to set the timeout time of the sample. If the completion time is too long, the preprocessor will schedule the timer task to interrupt the sample;

1. Let's take a look at what this Sample Timeout looks like. Path: Thread Group > Add > Preprocessor > Sample Timeout , 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;

Sample timeout: timeout time;

3.8BeanShell PreProcessor

BeanShell is a free java source code interpreter that supports object-based scripting languages ​​and can also be embedded in java source code. After adding the processor, you can directly write java code in it to realize the functional operation you want.

The usage is similar to the Beanshell sampler, you can refer to: Jmeter (fifteen) - from entry to master - JMeter import custom Jar package This article.

1. Let's first take a look at what this BeanShell PreProcessor looks like, the path: Thread Group > Add > Preprocessor > BeanShell Preprocessor , 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;

Language: language, the language selected for the development script, the JSR223 language used, can be selected according to needs;

Parameters: parameters, parameters passed to the script;

File Name: file name, locally developed script file (will overwrite the script written in JMeter);

Script compilation caching: Store compiled scripts, checked by default;

Script: To run the script. Scripting area.

4. Summary

  Well, all the preprocessors of JMeter have been introduced here today, thank you for your patient reading and learning.

 

Guess you like

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