Common 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 testplan
value add-> Config Element -> HTTP Request Defaults
setting example:
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
2. jmeter supports the setting of unified management parameters
a. Create HTTP Header Manager
Create path: testplan
Right-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
defined http header information manager interface
b. User-defined parameters
Create path: testplan
Right-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:
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:
Add shopping cart:
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 testplan
the 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 】
File content reference: that is, the content in the file only has data items, and there is no specification of variable names. The
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. json
Extractor
Create path: http请求
right-click add ->Post Processors ->JSON Extractor
jmeter
on 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}
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:jmeter
json
-
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.
Quote:
-
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
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
value:
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.
Logic controllers can also be nested.
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.