The format of the yaml file under the httprunner project
1. First create a new testcases folder under the python project, and then create a new file with a .yml suffix, such as demo01.yml
HttpRunner simulates sending get requests
config: Basic configuration information of the use case
name: test case name configuration
base_url: test host address
test: test steps
request: request information configuration
url: request address
method: request method
params: url parameters
headers: request headers
validate: assertion settings
Note: Frequent format errors: validate should be at the same level as request
- config: # Configuration information name: Test Baidu website # Test case name base_url: https://www.baidu.com # Host address - test: # Test step name: Interface name Baidu interface # Test step name request: # Request url : / # Request address method: GET # Request type validate: # Assertion settings - eq: [status_code,200]
HttpRunner simulates sending a get request with parameters
Sending a GET request can add parameters through params
# Send a GET request with parameters - config: name: "WeChat interface" # You can use no quotation marks, or use single quotation marks or double quotation marks. Note that the format should be consistent. base_url: "https://api.weixin.qq. com" - test: name: "Get token" request: url: "/cgi-bin/token" method: "GET" params: # parameter grant_type: "client_credential" appid: "wxf14419077f707856" secret: "92a113bd4b5ffdc72144740dc71 23c99" validate: - eq: ["status_code",200] - eq: ["content.expires_in",7200]
Execute the operation command of the yml file
Click the Terminal below in pycharm, enter the command httprunner yml test script path to execute, as shown in the figure below
If OK appears after the command is executed, it means the execution is successful, as shown in the figure below:
Automatically generate test reports:
At this time, a reports folder will be automatically generated under the httprunner project, and there will be executed test reports in it, as shown in the figure below:
Practical case
Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.
If it is helpful to you, please like and collect it to give the author an encouragement. It is also convenient for you to quickly find it next time.
If you don’t understand, please consult the small card below. The blogger also hopes to learn and progress with like-minded testers
At the right age, choose the right position, and try to give full play to your own advantages.
My road of automated test development is inseparable from the plan of each stage along the way, because I like planning and summarizing,
Test and develop video tutorials, study notes and receive portals! ! !