赞
踩
Httprunner说明文档路径:
https://docs.httprunner.org/
HttpRunner v3.x支持三种测试用例格式pytest,YAML和JSON。强烈建议以pytest格式而不是以前的YAML/JSON格式编写和维护测试用例
格式关系如下图所示:
httprunner3,要求python>=3.6,<4.0
pip3 install httprunner
# 已安装,升级到最新版本
pip3 install -U httprunner
pip3 install -U git+https://github.com/HttpRunner/HttpRunner.git@master
安装HttpRunner后,系统将添加5个命令。
httprunner:主命令,用于所有功能
hrun:的别名httprunner run,用于运行YAML / JSON / pytest测试用例
hmake:的别名httprunner make,用于将YAML / JSON测试用例转换为pytest文件
har2case:的别名httprunner har2case,用于将HAR转换为YAML / JSON测试用例
locusts:用于对locusts进行负载测试
httprunner startproject -h
D:\work\wy_only\httprunnerDemo>httprunner startproject -h
usage: httprunner startproject [-h] [project_name]
positional arguments:
project_name Specify new project name.
optional arguments:
-h, --help show this help message and exit
创建项目只需要一个参数(项目名称)
如: httprunner startproject httprunnerDemo
D:\work\wy_only\httprunnerDemo>har2case -h usage: har2case har2case [-h] [-2y] [-2j] [--filter FILTER] [--exclude EXCLUDE] [har_source_file] positional arguments: har_source_file Specify HAR source file optional arguments: -h, --help show this help message and exit -2y, --to-yml, --to-yaml Convert to YAML format, if not specified, convert to pytest format by default. -2j, --to-json Convert to JSON format, if not specified, convert to pytest format by default. --filter FILTER Specify filter keyword, only url include filter string will be converted. --exclude EXCLUDE Specify exclude keyword, url that includes exclude string will be ignored, multiple keywords can be joined with '|'
har2case ./har/dial.har -2y —生成dial.yml
har2case ./har/dial.har -2j —生成dial.json
har2case ./har/dial.har —生成dial_test.py
由于HttpRunner 3.0.7以后的版本,har2case默认情况下会将HAR文件转换为pytest
注意,hrun是的命令别名httprunner run,它们具有相同的作用。
hrun = httprunner run
hrun = make + pytest
运行命令等价:
$ hrun ./testcases/login_test.py
$ pytest ./testcases/login_test.py
$ hrun ./testcases/login.yml
主要讲解CSV格式,通过parameters关键字,参数列表中间加“-”串行。${P(CSV文件相对路径)}
config:
name: "business type info test"
variables:
username: "admin"
password: "2wsx@WSX"
parameters:
ids-combineNe-realNeType-slNeType: ${parameterize(data/base_ne/base_ne_ids.csv)}
# 两种格式:ids-combineNe-realNeType-slNeType: ${P(data/base_ne/base_ne_ids.csv)}
base_url: "http://192.xxx.xxx.xxx:8080"
verify: False
参数使用情况
- name: /base-ne/ids request: headers: Authorization: $token Content-Type: application/json method: GET params: ids: $ids url: /base-ne/ids validate: - eq: ["status_code", 200] - eq: - body.result[0].combineNe - $combineNe - eq: - body.result[0].realNeType - $realNeType - eq: - body.result[0].slNeType - $slNeType
CSV文件格式如下:
ids,combineNe,realNeType,slNeType
1,eNode/MME,MME,eNode
2,gNode/AMF,AMF,gNode
3,PGW/PBC,PBC,PGW
4,PSBC/I-CSF,I-CSF,PSBC
5,S-CSC/HSS,HSS,S-CSC
6,S-CSC/AS,AS,S-CSC
7,eNode/SGW,SGW,eNode
用例执行时,会运行七次。
Httprunner提供pytest默认的报告格式
hrun ./testcases/login.yml --html=reports/demo.html
运行用例:
pytest testcases/base_ne/base_ne_ids.pytest --alluredir reports (最终报告可以看到运行日志)
hrun testcases/base_ne --alluredir=reports (没有运行日志)
生成报告命令:
allure generate reports
allure generate reports -o allure-report --clean
-o allure-report:是指定清空测试报告的文件
–clean:是为了清空已有的测试报告
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。