The last lesson showed the basic usage of JMeter: recording and playback function, assertion and aggregation report. Professor Li Zhengdao talked about learning methods. He showed that we can get a lot of information.
However, there is still a way to go from understanding to understanding. Only through hands-on practice can we become understanding. Being able to obtain information does not mean understanding.
But how to pass get parameters correctly and how to use HTTP correctly. In particular, the interface is accessed without UI. The boy takes you to learn JMeter with comics, so that you can understand new knowledge in a relaxed environment.
To create a sampler, you only need two steps
-
Add Thread Group
-
Add "Http Request" Sampler
The following interface logic is as follows:
Interface introduction
The interface we use is our own program. Students can find other interfaces for training!
The following is the famous login interface:
Path: /api/v1/user/login Method: POST Header: { Content-Type : application/json } request body: "authRequest": { "userName": "{{login_email}}", "password": "{{login_pwd}}"}
We send a request to / api/v1/user/login. The sent header needs to include content type:
application/json, if the request body contains:
"authRequest": { "userName":"{{login_email}}", "password":
"{{login_pwd}}"}.
The server will give us a feedback. It will verify whether the mailbox and password are correct. If login_email and login_pwd error, we will get the following information of Fail:
Fail: { "code": "401", "message": "login fail"}
If login_email and login_ If pwd is correct, you will get the following information of Success:
Success: { "code": "200", "message": "login success", "access_token": "[access_token]" }
With this access_token, we got the license.
Browse menu interface
Path: /api/v1/menu/list Method: GET Header: { Content-Type : application/json, access_token : [access_token] } request parameter:type Optional parameters: breakfast, lunch, dinner - Success: { "breakfast": [{ "menu_nunber": "01", "menu_price": 5.50, "menu_name": "Steamed Dumplings"}, { "menu_nunber": "02", "menu_price": 3.00, "menu_name": "mixed congee" }, ...... ] }
Order confirmation interface
Path: /api/v1/menu/confirm Method: POST Header: { Content-Type : application/json, access_token : [access_token] } request body: { "order_list": [ { "menu_nunber" : "01", "number" : 1 }, { "menu_nunber" : "03", "number" : 2 } ] } Success : { "code": "200", "message": "Order success.", "total": 3 #Total order items} Fail : If header Medium access_token error { "code": "401", "message": "Please login first."}
Logoff interface
Path: /api/v1/user/logout Method: DELETE Header: { Content-Type : application/json, access_token : [access_token] } request parameter & body:None Success : { "code": "200", "message": "logout success"} Fail : If header Medium access_token error{ "code": "401", "message": "Unknown user info, logout fail."}
Request name defined in Sampler: user login
Configure Host, Port, Path = /api/v1/user/login
Configure Method = POST
Add request parameters to the body in HttpRequest
{
"authRequest": { "userName": "user01", "password": "pwd" }
}
Add Http Header Manager in Http Request to manage the header information of the request
Add "View Result Tree" to view request / response details
Configure the following parameters in Http Header Manager: content type: application/json
Run and check the run results in View Result Tree
Create a browse menu interface request and add an HttpRequest request. Configuration request Name: browse menu
Enter hostname, port, path = /api/v1/menu/list
Set Method = GET
Add Http Header Manager in HttpRequest and leave the Http Header Manager empty temporarily. We will configure it later
The return code is 401 and the prompt message is "Please login first.". Smart readers, can you answer the reason for the elephant?
I have created all interfaces and left the Http Header Manager empty for the time being:
To extract the JSON return value of the interface, you need to add a JSON Extractor (JSON extractor) to the corresponding HttpRequest
json path needs to be used to match the variable values to be extracted. Due to the limited space, I won't explain how to use json path. Please search by yourself.
$. Represents the root node of JSON. You can open JSON Path Tester in View Result Tree to determine the correctness of the matched JSON variable path
Fill in the JSON Extractor with the following information
-
Quantity name
-
JSON path expression
-
Match number
Add access to the header of the interface request_ Token variable. Method ${variable name} referencing variable in JMeter
Add the ${access_token} variable to the header in the browse menu interface, order confirmation interface and user logout interface
Run the debugging results. After the configuration is correct, the background interface can return the normal response result data
Write at the end
This paper shows you the advanced usage of JMeter in the form of cartoon: interface access without UI and parameter passing mechanism. Students, don't you know what you've learned? Please practice hard and strive to learn more knowledge. This content is from Hogwarts Testing Institute. Do you want to further learn the use of JMeter? Please continue to follow us.
Do you like this article?
Just click "watching" to encourage the kids * * *************
Come to Hogwarts test and development society to learn more advanced technologies of software testing and test development. The knowledge points include web automated testing, app automated testing, interface automated testing, test framework, performance testing, security testing, continuous integration / continuous delivery / DevOps, test left, test right, precision testing, test platform development, test management, etc, The course technology covers bash, pytest, junit, selenium, appium, postman, requests, httprunner, jmeter, jenkins, docker, k8s, elk, sonarqube, Jacobo, JVM sandbox and other related technologies, so as to comprehensively improve the technical strength of test and development engineers
QQ communication group: 484590337
The official account TestingStudio
Click for more information