ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

httprunner3.x全网最详细教程

2022-01-10 22:31:30  阅读:187  来源: 互联网

标签:kB 教程 httprunner demo 全网 testcase httprunner3 pytest packages


一、所需环境

  • wiindows10以上
  • python3.6以上
  • httprunner3.1.6(最新版本)
  • pycharm社区版

二、安装httprunner

1、卸载旧版本

卸载之前版本的命令为:pip3 uninstall httprunner

2、安装新版本

默认安装方式

pip3 install httprunner

以这种方式是默认安装最新版本的,并且是从国外服务器下载,但是偶尔会出现报错或者超时的情况,因此一般采用国内镜像安装,这里采用国内豆瓣源镜像安装。
一般安装命令:

pip3 install httprunner==3.1.6 -i https://pypi.douban.com/simple

此种方式是指定安装版本和安装源
安装完成后如下显示,表示安装成功

点击查看代码
C:\Users\fsy>pip3 install httprunner==3.1.6 -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting httprunner==3.1.6
  Downloading https://pypi.doubanio.com/packages/e4/2f/25011310f2f13f55de18845435f62b0ae16fbb69500885c268705ef42ee2/httprunner-3.1.6-py3-none-any.whl (60 kB)
     |████████████████████████████████| 60 kB 549 kB/s
Collecting requests<3.0.0,>=2.22.0
  Downloading https://pypi.doubanio.com/packages/2d/61/08076519c80041bc0ffa1a8af0cbd3bf3e2b62af10435d269a9d0f40564d/requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 584 kB/s
Collecting jmespath<0.10.0,>=0.9.5
  Downloading https://pypi.doubanio.com/packages/a3/43/1e939e1fcd87b827fe192d0c9fc25b48c5b3368902bfb913de7754b0dc03/jmespath-0.9.5-py2.py3-none-any.whl (24 kB)
Collecting pytest<6.0.0,>=5.4.2
  Downloading https://pypi.doubanio.com/packages/9f/f3/0a83558da436a081344aa6c8b85ea5b5f05071214106036ce341b7769b0b/pytest-5.4.3-py3-none-any.whl (248 kB)
     |████████████████████████████████| 248 kB 819 kB/s
Collecting sentry-sdk<0.15.0,>=0.14.4
  Downloading https://pypi.doubanio.com/packages/1b/95/9a20eebcedab2c1c63fad59fe19a0469edfc2a25b8576497e8084629c2ff/sentry_sdk-0.14.4-py2.py3-none-any.whl (104 kB)
     |████████████████████████████████| 104 kB 1.3 MB/s
Collecting black<20.0,>=19.10b0
  Downloading https://pypi.doubanio.com/packages/fd/bb/ad34bbc93d1bea3de086d7c59e528d4a503ac8fe318bd1fa48605584c3d2/black-19.10b0-py36-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 951 kB/s
Collecting pytest-html<3.0.0,>=2.1.1
  Downloading https://pypi.doubanio.com/packages/00/a7/34f195c514d39b4453619b3eb284989e5adb09a2a68ac09ce3779f9b9478/pytest_html-2.1.1-py2.py3-none-any.whl (16 kB)
Collecting pyyaml<6.0.0,>=5.1.2
  Downloading https://pypi.doubanio.com/packages/97/d3/24097209f6af04fcdbb40500480a0feaa62164e60bca4c9532f0e9354e47/PyYAML-5.4.1-cp38-cp38-win_amd64.whl (213 kB)
     |████████████████████████████████| 213 kB 3.3 MB/s
Collecting loguru<0.5.0,>=0.4.1
  Downloading https://pypi.doubanio.com/packages/b2/f4/2c8b94025c6e30bdb331c7ee628dc152771845aedff35f0365c2a4dacd42/loguru-0.4.1-py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 331 kB/s
Collecting jinja2<3.0.0,>=2.10.3
  Downloading https://pypi.doubanio.com/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 819 kB/s
Collecting pydantic<2.0,>=1.4
  Downloading https://pypi.doubanio.com/packages/5f/ca/ec4b2597b7ace79a05300a2e7eff8713b55745312b2acc89f74bf73f8dfc/pydantic-1.9.0-cp38-cp38-win_amd64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 1.3 MB/s
Collecting Brotli<2.0.0,>=1.0.9
  Downloading https://pypi.doubanio.com/packages/63/29/1b104b5915e61d9f7443889657d93937b7e0b33b331609b82693547934a0/Brotli-1.0.9-cp38-cp38-win_amd64.whl (365 kB)
     |████████████████████████████████| 365 kB 6.8 MB/s
Collecting attrs>=18.1.0
  Downloading https://pypi.doubanio.com/packages/be/be/7abce643bfdf8ca01c48afa2ddf8308c2308b0c3b239a44e57d020afa0ef/attrs-21.4.0-py2.py3-none-any.whl (60 kB)
     |████████████████████████████████| 60 kB 952 kB/s
Collecting typed-ast>=1.4.0
  Downloading https://pypi.doubanio.com/packages/93/6a/1b01a1864854fd6ed63e0e0649a9c1e4ef1425e417c43e7b09c0e4e7fdac/typed_ast-1.5.1-cp38-cp38-win_amd64.whl (164 kB)
     |████████████████████████████████| 164 kB 819 kB/s
Collecting click>=6.5
  Downloading https://pypi.doubanio.com/packages/48/58/c8aa6a8e62cc75f39fee1092c45d6b6ba684122697d7ce7d53f64f98a129/click-8.0.3-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 3.2 MB/s
Collecting appdirs
  Downloading https://pypi.doubanio.com/packages/3b/00/2344469e2084fb287c2e0b57b72910309874c3245463acd6cf5e3db69324/appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting regex
  Downloading https://pypi.doubanio.com/packages/e2/b1/b1d30513d3638e1e48cdfa5857a0e9c92ec7d19c0641836d0b49c4d00cac/regex-2021.11.10-cp38-cp38-win_amd64.whl (273 kB)
     |████████████████████████████████| 273 kB 731 kB/s
Collecting toml>=0.9.4
  Downloading https://pypi.doubanio.com/packages/44/6f/7120676b6d73228c96e17f1f794d8ab046fc910d781c8d151120c3f1569e/toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting pathspec<1,>=0.6
  Downloading https://pypi.doubanio.com/packages/42/ba/a9d64c7bcbc7e3e8e5f93a52721b377e994c22d16196e2b0f1236774353a/pathspec-0.9.0-py2.py3-none-any.whl (31 kB)
Collecting colorama
  Downloading https://pypi.doubanio.com/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=0.23
  Downloading https://pypi.doubanio.com/packages/30/9e/4b7116f464a0151b86ce42b5185941eb74c207b38fe033f71f5e5d150356/MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl (14 kB)
Collecting win32-setctime>=1.0.0
  Downloading https://pypi.doubanio.com/packages/37/6a/a498698d31626f32eae2c3bd1f1c303c6b3d54589b2993e9e05a4cd513dd/win32_setctime-1.0.4-py3-none-any.whl (3.5 kB)
Collecting typing-extensions>=3.7.4.3
  Downloading https://pypi.doubanio.com/packages/05/e4/baf0031e39cf545f0c9edd5b1a2ea12609b7fcba2d58e118b11753d68cf0/typing_extensions-4.0.1-py3-none-any.whl (22 kB)
Collecting wcwidth
  Downloading https://pypi.doubanio.com/packages/59/7c/e39aca596badaf1b78e8f547c807b04dae603a433d3e7a7e04d67f2ef3e5/wcwidth-0.2.5-py2.py3-none-any.whl (30 kB)
Collecting pluggy<1.0,>=0.12
  Downloading https://pypi.doubanio.com/packages/a0/28/85c7aa31b80d150b772fbe4a229487bc6644da9ccb7e427dd8cc60cb8a62/pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting atomicwrites>=1.0
  Downloading https://pypi.doubanio.com/packages/2c/a0/da5f49008ec6e9a658dbf5d7310a4debd397bce0b4db03cf8a410066bb87/atomicwrites-1.4.0-py2.py3-none-any.whl (6.8 kB)
Collecting packaging
  Downloading https://pypi.doubanio.com/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 2.7 MB/s
Collecting more-itertools>=4.0.0
  Downloading https://pypi.doubanio.com/packages/e5/c3/48e2c81038f57e8caab9a6e6fb6c2fc23536c59b092abefc447e6b5d1903/more_itertools-8.12.0-py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 1.9 MB/s
Collecting py>=1.5.0
  Downloading https://pypi.doubanio.com/packages/f6/f0/10642828a8dfb741e5f3fbaac830550a518a775c7fff6f04a007259b0548/py-1.11.0-py2.py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 2.6 MB/s
Collecting pytest-metadata
  Using cached https://pypi.doubanio.com/packages/e5/12/bfb677aad996cc994efb9c61289a4994d60079587e85155738859fd3b68e/pytest_metadata-1.11.0-py2.py3-none-any.whl (10 kB)
Collecting idna<4,>=2.5
  Downloading https://pypi.doubanio.com/packages/04/a2/d918dcd22354d8958fe113e1a3630137e0fc8b44859ade3063982eacd2a4/idna-3.3-py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 2.0 MB/s
Collecting urllib3<1.27,>=1.21.1
  Downloading https://pypi.doubanio.com/packages/4e/b8/f5a25b22e803f0578e668daa33ba3701bb37858ec80e08a150bd7d2cf1b1/urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 6.8 MB/s
Collecting charset-normalizer~=2.0.0
  Downloading https://pypi.doubanio.com/packages/84/3e/1037abe6498e65d645ce7a22d3402605d49a3b2c7f20c3abb027760da4f0/charset_normalizer-2.0.10-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
  Downloading https://pypi.doubanio.com/packages/37/45/946c02767aabb873146011e665728b680884cd8fe70dde973c640e45b775/certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
     |████████████████████████████████| 149 kB 3.2 MB/s
Collecting pyparsing!=3.0.5,>=2.0.2
  Downloading https://pypi.doubanio.com/packages/a0/34/895006117f6fce0b4de045c87e154ee4a20c68ec0a4c9a36d900888fb6bc/pyparsing-3.0.6-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 1.7 MB/s
Installing collected packages: pyparsing, wcwidth, py, pluggy, packaging, more-itertools, colorama, attrs, atomicwrites, pytest, win32-setctime, urllib3, typing-extensions, typed-ast, toml, regex, pytest-metadata, pathspec, MarkupSafe, idna, click, charset-normalizer, certifi, appdirs, sentry-sdk, requests, pyyaml, pytest-html, pydantic, loguru, jmespath, jinja2, Brotli, black, httprunner
Successfully installed Brotli-1.0.9 MarkupSafe-2.0.1 appdirs-1.4.4 atomicwrites-1.4.0 attrs-21.4.0 black-19.10b0 certifi-2021.10.8 charset-normalizer-2.0.10 click-8.0.3 colorama-0.4.4 httprunner-3.1.6 idna-3.3 jinja2-2.11.3 jmespath-0.9.5 loguru-0.4.1 more-itertools-8.12.0 packaging-21.3 pathspec-0.9.0 pluggy-0.13.1 py-1.11.0 pydantic-1.9.0 pyparsing-3.0.6 pytest-5.4.3 pytest-html-2.1.1 pytest-metadata-1.11.0 pyyaml-5.4.1 regex-2021.11.10 requests-2.27.1 sentry-sdk-0.14.4 toml-0.10.2 typed-ast-1.5.1 typing-extensions-4.0.1 urllib3-1.26.8 wcwidth-0.2.5 win32-setctime-1.0.4

3、查看版本号

hrun命令查看安装的httprunner版本号,或者用命令httprunner,效果是一样的

C:\Users\fsy>hrun -V
3.1.6
C:\Users\fsy>httprunner -V
3.1.6

至此,httprunner已经安装成功,安装成功后,httprunner会自动生成几个重要的命令,通过-h查看命令

C:\Users\fsy>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

可以看到生成了4个命令,分别是

  • run:运行测试用例的命令
  • startproject:创建测试模板项目的命令
  • har2case:将fiddler或者charles导出的文件转化成py文件的命令
  • make:将yaml文件的测试用例或者json文件的测试用例转化成pytest测试用例

三、创建项目

1、用命令startproject创建一个模板项目,进入到对应的目录下面,执行命令

D:\httprunnerStudy>httprunner startproject httprunner_demo
2022-01-09 13:25:30.189 | INFO     | httprunner.scaffold:create_scaffold:43 - Create new project: httprunner_demo
Project Root Dir: D:\httprunnerStudy\httprunner_demo

created folder: httprunner_demo
created folder: httprunner_demo\har
created folder: httprunner_demo\testcases
created folder: httprunner_demo\reports
created file: httprunner_demo\testcases\demo_testcase_request.yml
created file: httprunner_demo\testcases\demo_testcase_ref.yml
created file: httprunner_demo\debugtalk.py
created file: httprunner_demo\.env
created file: httprunner_demo\.gitignore

$ tree httprunner_demo -a
2022-01-09 13:25:30.205 | 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-Break to quit

从日志信息可以看到已经成功创建了一个项目,通过pycahrm打开创建的项目,看到项目结构如下

其中包含两个yml文件,这两个yml文件是官方给的示例,实际使用的时候可以删除掉,执行其中一个yml测试用例

 D:\httprunnerStudy> hrun D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_ref.yml
2022-01-09 13:31:48.546 | INFO     | httprunner.make:__make:512 - make path: D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_ref.yml
2022-01-09 13:31:48.556 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2022-01-09 13:31:48.561 | INFO     | httprunner.loader:load_dot_env_file:127 - Loading environment variables from D:\httprunnerStudy\httprunner_demo\.env
2022-01-09 13:31:48.566 | DEBUG    | httprunner.utils:set_os_environ:33 - Set OS environment variable: USERNAME
2022-01-09 13:31:48.566 | DEBUG    | httprunner.utils:set_os_environ:33 - Set OS environment variable: PASSWORD
2022-01-09 13:31:48.566 | INFO     | httprunner.make:make_testcase:349 - start to make testcase: D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_ref.yml
2022-01-09 13:31:48.586 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2022-01-09 13:31:48.586 | INFO     | httprunner.make:make_testcase:349 - start to make testcase: D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_request.yml
2022-01-09 13:31:48.586 | INFO     | httprunner.make:make_testcase:442 - generated testcase: D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_request_test.py
2022-01-09 13:31:48.596 | INFO     | httprunner.make:make_testcase:442 - generated testcase: D:\httprunnerStudy\httprunner_demo\testcases\demo_testcas2022-01-09 13:31:48.596 | INFO     | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ...
reformatted D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_ref_test.py
reformatted D:\httprunnerStudy\httprunner_demo\testcases\demo_testcase_request_test.py
All done! ✨ 

标签:kB,教程,httprunner,demo,全网,testcase,httprunner3,pytest,packages
来源: https://www.cnblogs.com/fsy-f4/p/15780748.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有