[jmeter] Use the result of the previous request as the parameter of the next request

1. Introduction
ApacheJMeter is a Java-based stress testing tool developed by the Apache organization. Used for stress testing software, it was originally designed for web application testing but has since been expanded to other testing areas. It can be used to test static and dynamic resources such as static files, Java servlets, CGI scripts, Java objects, databases, FTP servers, etc. JMeter can be used to simulate huge loads on servers, networks or objects, test their strength under different stress categories and analyze overall performance. In addition, JMeter can perform functional/regression testing of applications by creating scripts with assertions to verify that your program returns the results you expect. For maximum flexibility, JMeter allows assertions to be created using regular expressions. Apachejmeter can be used to test the performance of static and dynamic resources (files, Servlets, Perl scripts, Java objects, databases and queries, FTP servers, etc.). It can be used to simulate heavy loads on servers, networks or objects to test their strength or analyze overall performance under different stress types. You can use it to do graphical analysis of performance or test your servers/scripts/objects under large concurrent loads.

2. Purpose
: It can perform stress and performance testing on HTTP and FTP servers, and can also perform the same test on any database (via JDBC).

Completely portable and 100% pure Java.

Full Swing and lightweight component support (precompiled JARs using javax.swing.*) packages.

The fully multi-threaded framework allows concurrent sampling through multiple threads and simultaneous sampling of different functions through separate groups of threads.

​Careful GUI design allows for fast operation and more precise timing.

Caching and offline analysis/playback of test results.

3. Download and simple application.
For download and simple application, please refer to: http://www.cnblogs.com/0201zcr/p/5046193.html

4. How to use the result of the previous request as the parameter of the next request
. During stress testing, it is often necessary to connect several processes in series to pass the program test. For example: My current user needs to log in first and obtain my login credentials (tokenId). Later, I need to bring this credentials when requesting other resources. To identify whether you are a legitimate user.

1) Create a thread rent

2) Create a request to obtain credentials

3) Create a post-processor

Right-click the sampler in the JMeterGUI view to open the right-click menu -> Add -> Post-processor -> Regular Expression Extractor, open the "Regular Expression Extractor" session page and edit its content as follows:

The post-processor is what needs to be done when the request returns. Here I want to get the tokenId we want from the returned content. Here we use the "regular expression extractor" to get the content we want using regular expressions.

4) Regular expression extractor configuration

The reference name is the variable name that will be referenced in the next request;

​Regular expressions are regular expressions that extract the content you want. Parentheses () represent extraction, which means that you need to enclose the content you want to extract;

The template uses the extracted value. Because there may be multiple values ​​matching, a template is used. Matching starts from 1 and so on. There is only one here, so just fill in $1$;

​Matching numbers indicate how to take the value. 0 represents a random value, 1 represents all values. There is only one here, just fill in 1;

The default value means that if the parameter does not have a value, the default value is given to it. Generally leave it blank.

The data returned by this request is as follows:

<span style="background-color:#f8f8f8"><span style="color:#333333">{"message":"success","statusCode":200,"registerDay":"20","tokenId":"bf1017bc1bb495ae31764b306a3422885f5"}</span></span>

What we want to get now is the value of tokenId in the above json string, which is bf1017bc1bb495ae31764b306a3422885f5.

5) Add next request

In this request, we need to send the above tokenId as a parameter.

Same as above 2) Add an http request (right click on the thread -> Add -> Sampler -> HTTP request)

6) Add view result tree

 7) After execution, you can query through "View Result Tree"

The following are supporting learning materials. For those who are doing [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you!

Guess you like

Origin blog.csdn.net/2301_76643199/article/details/133362506