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
  1. run:使HttpRunner测试用例并与pytest一起运行。
  2. startproject:用模板结构创建一个新项目。
  3. har2case:将HAR(HTTP Archive)转换为HttpRunner的YAML / JSON测试用例。
  4. 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又高大上了不少。

以上总结或许能帮助到你,或许帮助不到你,但还是希望能帮助到你,如有疑问、歧义,评论区留言会及时修正发布,谢谢!


未完,待续…

一直都在努力,希望您也是!

在这里插入图片描述

上一篇:httprunner3.x .har文件处理运行
下一篇:web自动化测试清除可视化界面

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年04月19日 12时35分57秒