httprunner3.x安装及运行

 

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 -V
3.1.4
  • hrun -V # httprunner 的别名
(venv) lifeng@apple httprunnerDemo % hrun -V
3.1.4

 

显示帮助信息:

(venv) lifeng@apple httprunnerDemo % httprunner -h
usage: 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用例。

 

 

httprunnrr startproject xxxxx,快速创建项目工程目录

(venv) lifeng@apple apiHttprunner3.0 % httprunner startproject testDemo
2021-03-22 23:23:11.298 | INFO     | httprunner.scaffold:create_scaffold:43 - Create new project: testDemo
Project Root Dir: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo

created folder: testDemo
created folder: testDemo/har
created folder: testDemo/testcases
created folder: testDemo/reports
created file: testDemo/testcases/demo_testcase_request.yml
created file: testDemo/testcases/demo_testcase_ref.yml
created file: testDemo/debugtalk.py
created file: testDemo/.env
created file: testDemo/.gitignore

$ tree testDemo -a
2021-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 messages
Waiting up to 2 seconds
Press 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/testDemo
2021-03-22 23:27:38.706 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2021-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/.env
2021-03-22 23:27:38.711 | DEBUG    | httprunner.utils:set_os_environ:33 - Set OS environment variable: USERNAME
2021-03-22 23:27:38.711 | DEBUG    | httprunner.utils:set_os_environ:33 - Set OS environment variable: PASSWORD
2021-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.yml
2021-03-22 23:27:38.726 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2021-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.yml
2021-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.py
2021-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.py
2021-03-22 23:27:38.742 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2021-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.yml
2021-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.py
reformatted /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0/testDemo/testcases/demo_testcase_request_test.py
All 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.1
rootdir: /Users/lifeng/python-projects/AuomationTest/apiHttprunner3.0
plugins: allure-pytest-2.8.34, metadata-1.11.0, html-2.1.1
collected 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又高大上了不少。

 

 

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


未完,待续…

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

 

转载请附带原文链接 ( https://www.cnblogs.com/lifeng0402/articles/14571964.html ),否则追究法律责任,谢谢!

 

posted @ 2021-03-24 08:18  一名小测试  阅读(12)  评论(0)    收藏  举报