Jmeter uses the result of the previous request as the parameter of the next request

background

When performing interface testing, it is often necessary to bring the result of the previous request as a parameter of the next request, such as the token after login.
In jmeter, there are two ways to achieve this function:

  • Regular Expression Extractor
  • json path extractor

For those whose return format is json, it is recommended to use the json path extractor.
First create a new thread group, and then add two http request samples respectively

 Here we can see that the first request is used to obtain the token, and the second request to obtain the user list uses the token returned by the first request.
The token is placed in the request header here, so you need to add an http header manager sample.

 Since subsequent requests need to use tokens for access, the request header is placed in front of subsequent requests, so that there is no need to add an http header manager sample for each request. Here you can refer to the component scope

Right-click the request that needs to be extracted to add a json path extractor

 After the addition is successful, the following picture is shown:

name of created variables: fill in the variable name here, that is, the value filled in when this parameter needs to be used later
json path expressions: fill in the expression of the json value to be extracted json expression syntax reference

If my blog is helpful to you, if you like my blog content, please "Like", "Comment", "Favorite" with one click!

Finally, basic knowledge, Linux essentials, Shell, Internet program principles, Mysql database, packet capture tool topics, interface testing tools, advanced testing-Python programming, Web automated testing, APP automated testing, interface automated testing, testing advanced continuous integration, Test framework development test framework, performance testing, security testing and other learning resources.

 

Guess you like

Origin blog.csdn.net/lzz718719/article/details/130976823