HttpRunner uses document cases to record and convert the problems and solutions in the process of generating test cases

Continued above, after successful startup, according to the user manual, start to capture the interface with the packet capture tool

Type directly in the browser:

http://127.0.0.1:5000/api/get-token
http://127.0.0.1:5000/api/users/1000

It cannot be executed successfully, I only open the api_server.py source file to see how the interface is written,

Find the interface document in the directory: HttpRunner \ tests \ api, view the interface information, only to know that both headers and body need to add content, and can not directly capture the package through the browser operation, so later by configuring the interface in postman After the execution is successful, the request issued by the postman captured by the packet capture tool.

The information added in the http://127.0.0.1:5000/api/get-token header file is as follows:

Headers: 
    Content-Type:application/json
    app_version:2.8.6
    os_platform:ios
    user_agent:iOS/10.3
    device_sn:FwgRiO7CNA50DSU

But in Body, you also need the value of sign. This value is calculated by the last four parameters in the header file, so I changed a line of code in api_server.py to print it out.

Modifications in the code:

The following picture shows the printed sign information:

Copy the printed sign information to the body in the figure below, and send the request successfully!

After doing this, the request http://127.0.0.1:5000/api/get-token is executed successfully.

For http://127.0.0.1:5000/api/users/1000 , configure the request header as follows:

Body content:

In the Charles packet capture tool, these two requests sent by postman are captured and exported to .har format, and the preparation of the test in the manual is finally done.

If you are using the fiddler tool to capture packets, select the file format when saving the file: HTTPArchive v1.2

After saving to .har, you can perform format conversion. I chose to convert to .yml format:

har2case D:\httprunner\demo-quickstart.har -2y

 

The output file path is also given and can be used.

Published 8 original articles · won 27 · views 1500

Guess you like

Origin blog.csdn.net/niuhaoyuan/article/details/105273815