
httprunner3.x安装及运行
发布日期:2021-05-13 21:48:58
浏览次数:24
分类:精选文章
本文共 5999 字,大约阅读时间需要 19 分钟。
–
httprunner是一个开源框架,只需编写维护一份 YAML/JSON 脚本,从1.x到现在的3.x也在不断地优化更新,3.x版本继续继承优秀的request库并增加了pytest框架、allure报告、locust性能等,集接口、性能、自动化测试为一体的多种需求测试,当然也肯定是支持持续集成的。
安装httprunner:
pip3 install httprunner
更新httprunner:
pip3 install -U httprunner
检查安装版本命令:
- httprunner -V
(venv) lifeng@apple httprunnerDemo % httprunner -V3.1.4
- hrun -V # httprunner 的别名
(venv) lifeng@apple httprunnerDemo % hrun -V3.1.4
显示帮助信息:
(venv) lifeng@apple httprunnerDemo % httprunner -husage: httprunner [-h] [-V] { run,startproject,har2case,make} ...One-stop solution for HTTP(S) testing.positional arguments: { run,startproject,har2case,make} sub-command help run Make HttpRunner testcases and run with pytest. startproject Create a new project with template structure. har2case Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner. make Convert YAML/JSON testcases to pytest cases.optional arguments: -h, --help show this help message and exit -V, --version show version
- run:使HttpRunner测试用例并与pytest一起运行。
- startproject:用模板结构创建一个新项目。
- har2case:将HAR(HTTP Archive)转换为HttpRunner的YAML / JSON测试用例。
- make:将YAML / JSON测试用例转换为pytest用例。
har2case这种文件可以直接在charles抓包工具上直接导出,格式选.har保存:
![]()
httprunnrr startproject xxxxx,快速创建项目工程目录
(venv) lifeng@apple apiHttprunner3.0 % httprunner startproject testDemo2021-03-22 23:23:11.298 | INFO | httprunner.scaffold:create_scaffold:43 - Create new project: testDemoProject Root Dir: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemocreated folder: testDemocreated folder: testDemo/harcreated folder: testDemo/testcasescreated folder: testDemo/reportscreated file: testDemo/testcases/demo_testcase_request.ymlcreated file: testDemo/testcases/demo_testcase_ref.ymlcreated file: testDemo/debugtalk.pycreated file: testDemo/.envcreated file: testDemo/.gitignore$ tree testDemo -a2021-03-22 23:23:11.303 | WARNING | httprunner.scaffold:show_tree:29 - tree command not exists, ignore.Sentry is attempting to send 0 pending error messagesWaiting up to 2 secondsPress Ctrl-C to quit
创建项目工程目录的同时,文件夹中也附带了用例模版,可以直接输入命令运行检验搭建是否有问题出现:
(venv) lifeng@apple apiHttprunner3.0 % hrun testDemo 2021-03-22 23:27:38.699 | INFO | httprunner.make:__make:512 - make path: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo2021-03-22 23:27:38.706 | INFO | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v22021-03-22 23:27:38.711 | INFO | httprunner.loader:load_dot_env_file:127 - Loading environment variables from /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/.env2021-03-22 23:27:38.711 | DEBUG | httprunner.utils:set_os_environ:33 - Set OS environment variable: USERNAME2021-03-22 23:27:38.711 | DEBUG | httprunner.utils:set_os_environ:33 - Set OS environment variable: PASSWORD2021-03-22 23:27:38.713 | INFO | httprunner.make:make_testcase:349 - start to make testcase: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_ref.yml2021-03-22 23:27:38.726 | INFO | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v22021-03-22 23:27:38.727 | INFO | httprunner.make:make_testcase:349 - start to make testcase: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_request.yml2021-03-22 23:27:38.728 | INFO | httprunner.make:make_testcase:442 - generated testcase: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_request_test.py2021-03-22 23:27:38.729 | INFO | httprunner.make:make_testcase:442 - generated testcase: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_ref_test.py2021-03-22 23:27:38.742 | INFO | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v22021-03-22 23:27:38.743 | INFO | httprunner.make:make_testcase:349 - start to make testcase: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_request.yml2021-03-22 23:27:38.743 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ...reformatted /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_ref_test.pyreformatted /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_request_test.pyAll done! ✨ 🍰 ✨2 files reformatted.2021-03-22 23:27:39.323 | INFO | httprunner.cli:main_run:56 - start to run tests with pytest. HttpRunner version: 3.1.4============================================================================================ test session starts ============================================================================================platform darwin -- Python 3.9.2, pytest-5.4.3, py-1.10.0, pluggy-0.13.1rootdir: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0plugins: allure-pytest-2.8.34, metadata-1.11.0, html-2.1.1collected 2 items testDemo/testcases/demo_testcase_request_test.py . [ 50%]testDemo/testcases/demo_testcase_ref_test.py . [100%]============================================================================================= 2 passed in 9.24s =============================================================================================
控制台还显示了详细的log日志,个人感觉比2.x又高大上了不少。
以上总结或许能帮助到你,或许帮助不到你,但还是希望能帮助到你,如有疑问、歧义,评论区留言会及时修正发布,谢谢!
未完,待续…
一直都在努力,希望您也是!
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2025年04月19日 12时35分57秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
线程学习5
2021-05-14
[Java Path Finder][JPF学习笔记][7]JPF输出详细程度设置
2021-05-14
GitHub完整记录数据库GHTorrent的下载和安装经验
2021-05-14
SKLearn中SVM参数自动选择的最简单示例(使用GridSearchCV)
2021-05-14
设计模式—— 三:依赖倒置原则
2021-05-14
SpringBoot打包之后乱码
2021-05-14
因SGA分配错误无法启动数据库
2021-05-14
Oracle修改字段类型方法总结
2021-05-14
ORA-00020 超过当前最大连接数
2021-05-14
合理控制oracle数据库具有DBA权限的用户
2021-05-14
【Android】源码分析 - Activity启动流程
2021-05-14
喝红茶是否会上火
2021-05-14
数据请求结构和返回结构
2021-05-14
Android进阶解密读书笔记1——第1章:Android系统架构
2021-05-14
Android进阶解密读书笔记2——第2章:Android系统启动——第1、2小节
2021-05-14
Java 位运算符表示多种状态
2021-05-14
GreenDao之注解
2021-05-14
Android使用Font Awesome
2021-05-14