一、介绍HttpRunner
HttpRunner是一款简单的Http(s)的测试框架;
根据HAR(接口文件)来自动生成yaml、json、.py三种格式测试用例,支持创建复杂的测试方案;
使用Pytest来进行测试,还可以自动生成优美的测试报告;
二、安装HttpRunner框架 1、安装 $ pip3 install Httprunner #通过pip安装 $ pip3 install git+https://github.com/httprunner/httprunner.git@master #根据git路径上安装最新版
2、更新
$ pip3 install -U httprunner #更新到最新版
$ pip3 install -U git+https://github.com/httprunner/httprunner.git@master #通过git路径进行更新
3、检查安装是否成功
$ httprunner -V
3.1.0 #出现版本号就已经成功了
4、想要查看HttpRunner有哪些可用的模块
$ 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
三、创建新项目
$ httprunner startproject demo #创建demo项目
2020-06-15 11:53:25.498 | INFO | httprunner.scaffold:create_scaffold:37 - Create new project: demo
Project Root Dir: /Users/debugtalk/MyProjects/HttpRunner-dev/HttpRunner/demo
created folder: demo
created folder: demo/har
created folder: demo/testcases
created folder: demo/reports
created file: demo/testcases/demo_testcase_request.yml
created file: demo/testcases/demo_testcase_ref.yml
created file: demo/debugtalk.py
created file: demo/.env
created file: demo/.gitignore
$ tree demo -a #查看项目数
demo
├── .env
├── .gitignore
├── debugtalk.py
├── har
├── reports
└── testcases
├── demo_testcase_ref.yml
└── demo_testcase_request.yml
3 directories, 5 files
四、运行项目
$ hrun demo/YAML/JSON文件路径
五、根据HAR文件生成测试用例 1、通过Fiddler/Postman工具进行抓取接口并进行导出HAR文件
2、生成测试用例
$ har2case HAR文件路径 #生成.py文件
$ har2case HAR文件路径 -2y/--to-yml #生成YAML文件
$ har3case HAR文件路径 -2j/--to-json #生成JSON文件
|