Jmeter interface automated testing - the use of Jmeter variables

When using jmeter for interface testing, we will inevitably encounter situations where we need to obtain test data from the context. At this time, we need to introduce variables.

define variable

use variables

How to call variables: ${variable name}
Scope of variables: Variables can be written into any field of any test component (except TestPlan).
Take the blog garden interface as an example:

Url: https://recomm.cnblogs.com/api/v2/recomm/blogpost/reco

HTTP Method: Post

Request:
{"itemId":11343866,"itemTitle":"Jmeter 01 Jmeter下载安装及入门"}

Response:
[{"itemId":"8971531","title":"使用JMeter进行压力测试","content":null,"url":"https://www.cnblogs.com/stulzq/p/8971531.html"},{"itemId":"4709031","title":"JMeter入门","content":null,"url":"http://www.cnblogs.com/s380774061/p/4709031.html"},{"itemId":"9413237","title":"Jmeter下载安装配置及使用(windows)","content":null,"url":"https://www.cnblogs.com/fanbi/p/9413237.html"},{"itemId":"5639895","title":"Jmeter使用入门","content":null,"url":"http://www.cnblogs.com/ceshisanren/p/5639895.html"},{"itemId":"7094047","title":"JMeter入门","content":null,"url":"http://www.cnblogs.com/iceb/p/7094047.html"}]


 

get variable from context

For example, in the above interface, we want to request again, and the request needs to be obtained from the previous response data. For example, we need the itemId and title in the response of the first request as the request for the next request

{"itemId":"8971531","title":"使用JMeter进行压力测试","content":null,"url":"https://www.cnblogs.com/stulzq/p/8971531.html"}

Then you need to use a configuration element JSON extractor.
Right-click http request->add->post processor->json extractor


JSON extractor parameter description:

parameter illustrate
Apply to
Main sample and sub-samples Main sample and sub-sample
Main sample only main sample
Sub-samples only child sample
JMeter Variable Name to use variable name
JSON Path Expression JSON expression (where is the value you want to get in the response data)
Match No.(0 or Random) Matching number, not filling in is to get the first one that meets the conditions, 0 is random, N is the Nth one, -1 is to get all
Compute comcatemation var(suffix_ALL) If many results are found, the plugin will concatenate them using ',' delimiter and store it in a variable called <variable name>_ALL
Default Values The default value when no parameter value is obtained

Finally: In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/IT_LanTian/article/details/131597547