新冠疫情刚爆发的时候,居家隔离很无聊,于是想用Python写个自动化测试框架。参考Jmeter的方式,Jmeter测试脚本是XML格式的文件,这个框架的脚本用YAML格式。 源码地址:https://github.com/momo3507/HttpCase.git
简介
使用YAML定义自动化测试用例,完了。
使用说明
from httpcase.project import Project
testcase = "httpcase.yml"
project = Project(testcase)
project.run()
脚本模板及说明
project: 我的HttpCase项目
variables:
username: wangwei
password: 1111
HttpRequestDefaults:
protocol: http
ip: 127.0.0.1
port: 5000
HttpHeaderDefaults:
Content-Type: application/json
token: 1ytd234567qwert
testsuites:
-
name: 用户登录模块
variables: {}
testcases:
-
name: 登录后进行查询
description: 测试xx情况下,功能是否正常
variables: {}
httpsteps:
-
name: 登录平台
protocol:
ip:
port:
method: POST
path: /login
params:
t: ${__timeStamp()}
body:
username: ${username}
password: ${password}
extract:
ret: $.ret
token: $.token
assertion:
- eq:
- status_code
- 200
- eq:
- ${ret}
- 0
- name: 查询用户
protocol:
ip:
port:
method: GET
path: /query
params:
t: ${__timeStamp()}
token: ${token}
body:
extract:
ret: $.ret
assertion:
- eq:
- status_code
- 200
- eq:
- ${ret}
- 0
|