jmeter notes 3: commonly used jmeter functions (with scenarios)

1. Other features of jmeter

1. There are multiple requested interfaces and the domain names are the same.

You can write it into the http request default value [Main parts to fill in: communication protocol, requested content encoding, server domain name]; create path: Right-click the content
panel testplanvalue add-> Config Element -> HTTP Request Defaults
setting example:
Insert image description here
In this way, the http request does not need to write the domain name, you only need to write Request method, request path and input parameters
Insert image description here

2. jmeter supports the setting of unified management parameters
a. Create HTTP Header Manager

Create path: testplanRight-click add -> Config Element -> HTTP Header Manager
content settings: its settings are in the form of key and value. When calling an http request, you can regard this object as a tool, defined in testplan, as a global variable. Usage scenario: user authentication
information Need to be used as a global variable for other interfaces to use

Detailed description:
When the interface requires user authentication (BeanShell PreProcessor, defined here on the http request)
authentication code sample
Insert image description here
defined http header information manager interface
Insert image description here

b. User-defined parameters

Create path: testplanRight-click and assign add-> Config Element ->User Defined Variables
the value in the form of key and value.
Applicable scenarios: You can define some product IDs, skuid, etc. here to facilitate other interfaces to be called as input parameters. It probably looks
like this:
Insert image description here

Usage scenario 1:
The application of user parameter variables includes but is not limited to http interface request parameters.
Variable values ​​to be used in http interface requests:
Insert image description here
Add shopping cart:
Insert image description here
Usage scenario 2:
Request path with variables, eg: such as www.baidu.${ a}, the value of a is com
jmeter can set the value in the user variable parameter, and then get it here for use.

c. csv data file settings

Create path: In testplanthe right-click add->Config Element -> CSV Data Set Config
interface parameters, see:
Sharing mode in the last column, which can specify the scope of the csv file data. Value range: All threads, Current thread group, Current thread, Edit [This item is the expandable item setting of the scope 】
Insert image description here
File content reference: that is, the content in the file only has data items, and there is no specification of variable names. The
Insert image description here
above methods of defining variables can be used to ${变量名}obtain values ​​in the form of :.

As for whether it is global or local, it depends on the location of the definition and the scope of the setting parameters.

3. The return value of interface a is used as the input parameter of interface b.
a. jsonExtractor

Create path: http请求right-click add ->Post Processors ->JSON Extractor
jmeteron it to realize its function: the return value of the previous interface is the input parameter of other interfaces.
Setting the interface value: Create a variable name in the figure below token, and the referenced place can be written${token}
Insert image description here

ps: If it is an object, you can get the value directly. $.data.字段
If it is an array,$.data[0].字段

  • Scenario 1: The order number of the order interface is used as the input parameter of the logistics information query interface. The extractor can be used
    here to transfer values ​​between interfaces and create a json extractor:jmeterjson

  • Scenario 2: The token returned after the user logs in. When modifying the user's mobile phone number, the http header manager needs to use the token information.
    Insert image description here
    Quote:
    Insert image description here

  • Scenario 3 The return value of the a interface is the field value in the array that is required by the b interface.
    The hierarchical structure of the interface return value: want to get
    Insert image description here
    the value of the id json extractor:$.data.order[0].merchant.id

b. Regular expressions

Creation path: add->Post Processors -> Regular Expression Extractor
Interface value setting: "cartId":"(.+?)"
I won’t explain too much about regular here. If you want to know more, you can refer to: jmeter regular
Insert image description here
value:
Insert image description here

4、if controller

Create path: right click on the thread groupadd->Logic Controller -> If Controller

Scenario 1, meeting certain conditions will trigger the call of certain interface(s)

This is just a simple use of logic controllers. If you want to know more, please refer to: jmeter logic controller.
Insert image description here
Logic controllers can also be nested.
Insert image description here

If you want to know more, you can visit
jmeter’s official website.
Students who want to know more can pay attention to this part of the official website.Insert image description here

Guess you like

Origin blog.csdn.net/qq_17033579/article/details/131878011