httprunner是一款面向https协;议的通用开源测试框架,支持三种用例:yaml/json/pytest代码,即可实现自动化测试、持续集成等多种测试需求
httprunner | 参数名 | 功能 | |
-V --version | 查看版本号 | ||
-h,--help | 查看帮助 | ||
run | 运行yaml,json,pytest测试用例 | httprunner run xxx.py | |
startproject | 使用模板结构创建新项目 | httprunner starproject 项目名称 | |
har2case | HAR转成yaml/json | httprunner run har2case.har | |
make | yaml/json测试用例转成pytest用例 | httprunner make 包名称 |
har2case | 参数名 | 功能 | |
-2y | 将bar数据转换成yaml文件格式 | har2case -2y xxx.har | |
-2j | 将bar数据转换成json文件格式 | har2case -2j xxx.har | |
--filter | 执行用例时只执行包含xxx地址的用例 | har2case -2y xxx.har --filter 49.235.92.12:8201 | |
--exclude | 执行用例时不执行包含xxx地址的用例 | har2case -2y xxx.har --exclude www.baidu.com |
测试用例结构
get_params.yaml文件
config:
name:get_goods
teststeps:
-
name:step_goods
request:
method:GET
url:https://
params:
page: 1
size: 2
validate:
- eq:[status_code,200]
- eq:[body.code,0]
- eq:[body.msg,success]
命令行运行 hrun testcase/get_params.yaml
get_params.yaml文件
将base_url提到config中
config:
name:get_goods
base_url:https://xx.xxx.xx.x:8001
teststeps:
-
name:step_goods
request:
method:GET
url:/api/v1/goods
params:
page: 1
size: 2
validate:
- eq:[status_code,200]
- eq:[body.code,0]
- eq:[body.msg,success]
命令行运行 hrun testcase/get_params.yaml
get_https.yaml
需要验证证书
config:
name:https_blog
teststeps:
-
name:https_blog
request:
method:GET
url:https://
verify:False
login_urlencoded.yaml
post请求
config:
name:login-v4
teststeps:
-
name:step-login
request:
method:POST
header:
Content-type:
url:https://
data:
username:admin
password:"123456"
login_urlencoded.yaml
post请求-全局变量
config:
name:login-v4
variables:
user:test1
psw:"12356"
teststeps:
-
name:step-login
request:
method:POST
header:
Content-type:
url:https://
data:
username:$user
password:%psw
validata 校验结果
使用jmespath提取JSON影响正文并使用预期值进行验证
1.jmes_path:jmespath表达式
2.expect预期值:这里也可以使用指定的预期值、变量或函数引用
3.message消息(可选):用于指定断言错误原因
validate:
- eq:[status_code,200]
- eq:[headrs. Content-type,applicatin/json]
- eq:[body.code,0]
- eq:[body.msg,success]