基于httprunner的接口测试
程序员文章站
2024-03-21 23:19:04
...
环境:Ubuntu
- 安装
sudo pip3 install httprunner==2.5.7
在 HttpRunner 安装成功后,系统中会新增如下 5 个命令:
httprunner: 核心命令
ate: 曾经用过的命令(当时框架名称为 ApiTestEngine),功能与 httprunner 完全相同
hrun: httprunner 的缩写,功能与 httprunner 完全相同
locusts: 基于 Locust 实现性能测试
har2case: 辅助工具,可将标准通用的 HAR 格式(HTTP Archive)转换为YAML/JSON格式的测试用例
- 实例操作
TesterHome 登录
功能描述:
- 进入登录页面
- 输入账号和密码
- 点击【Sign In】进行登录
Charles 抓包生成 HAR 文件
点击文件, 导出session,保存为har格式。
转化为yaml文件
har2case docs/data/testerhome-login.har -2y
执行, 生成html格式的report,在reports目录下
$ hrun testerhome-sign_in.yml
INFO HttpRunner version: 2.5.7
INFO Start to run testcase: testcase description
/account/sign_in
INFO GET https://testerhome.com/account/sign_in
INFO status_code: 200, response_time(ms): 179.4 ms, response_length: 12115 bytes
.
/account/sign_in
INFO POST https://testerhome.com/account/sign_in
INFO status_code: 200, response_time(ms): 231.92 ms, response_length: 89 bytes
.
/
INFO GET https://testerhome.com/
INFO status_code: 200, response_time(ms): 157.67 ms, response_length: 51701 bytes
.
----------------------------------------------------------------------
Ran 3 tests in 0.577s
OK
INFO Start to render Html report ...
INFO Generated Html report: ./reports/20200610T031226.611388.html
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
$
性能测试:
HttpRunner 通过复用 Locust
,可以在无需对 YAML/JSON 进行任何修改的情况下,直接运行性能测试。
$ locusts -f example-api-test.yml --processes 4
HttpRunner version: 2.5.7
[2020-06-10 11:18:20,853] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting web monitor at http://*:8089
[2020-06-10 11:18:20,854] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,877] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
[2020-06-10 11:18:20,878] wuzhiguo-Lenovo-B490/INFO/locust.main: Starting Locust 0.14.6
下一篇: 迭代法求模型的参数