httprunner小试
版本说明
python: 3.7.4
httprunner:3.1.4
har2case:0.3.1
pytest-html 2.1.1
------------------------------------------------------------------------------------------------------------------
安装httprunner第三方库
pip install httprunner
安装har2case
pip install har2case
查看是否安装成功
抓包工具抓取接口并导出,导出格式必须为har
使用har2case命令,将har格式的接口文件转换成测试用例
默认转换成json
命令:har2case 111.har
转换成yml格式的文件
命令:har2case 111.har -2y
运行测试
第一种:使用hrun命令运行生成的yml文件,运行后生成py文件
C:\Users\wwwww\PycharmProjects\MyJob\testcase>hrun 111.yml 2020-11-04 16:11:57.560 | INFO | httprunner.maked:\python\python37-32\lib\site-packages\urllib3\request.py:171: InvalidProxyConfigurationWarning: Your proxy configuration specified an HTTPS scheme for the proxy. Are you sure you want to use HTTPS to contact the proxy? This most likely indicates an error i n your configuration. Read this issue for more info: https://github.com/urllib3/urllib3/issues/1850 return self.urlopen(method, url, **extra_kw) :__make:512 - make path: C:\Users\wwwww\PycharmProjects\MyJob\testcase\111.yml 2020-11-04 16:11:57.567 | INFO | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2 2020-11-04 16:11:57.572 | INFO | httprunner.make:make_testcase:349 - start to make testcase: C:\Users\wwwww\PycharmProjects\MyJob\testcase\111.yml 2020-11-04 16:11:57.577 | INFO | httprunner.make:make_testcase:442 - generated testcase: C:\Users\wwwww\PycharmProjects\MyJob\testcase\T111_test.py 2020-11-04 16:11:57.579 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ... reformatted C:\Users\wwwww\PycharmProjects\MyJob\testcase\T111_test.py All done! ✨ 🍰 ✨ 1 file reformatted. 2020-11-04 16:11:58.187 | INFO | httprunner.cli:main_run:56 - start to run tests with pytest. HttpRunner version: 3.1.4 ================================================================== test session starts =================================================================== platform win32 -- Python 3.7.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 rootdir: C:\Users\wwwww\PycharmProjects\MyJob\testcase plugins: html-2.1.1, metadata-1.10.0 collected 1 item T111_test.py . [100%] =================================================================== 1 passed in 0.21s ==================================================================== Sentry is attempting to send 0 pending error messages Waiting up to 2 seconds Press Ctrl-Break to quit 2020-11-04 16:11:58.4822020-11-04 16:11:58.4862020-11-04 16:11:58.5162020-11-04 16:11:58.5172020-11-04 16:11:58.5192020-11-04 16:11:58.5212020-11-04 16:11: 58.5222020-11-04 16:11:58.5232020-11-04 16:11:58.5242020-11-04 16:11:58.5242020-11-04 16:11:58.525
第二种,使用hrun命令运行json文件
C:\Users\wwwww\PycharmProjects\MyJob\testcase>hrun 111.json 2020-11-04 16:41:49.751 | INFO | httprunner.make:__make:512 - make path: C:\Users\wwwww\PycharmProjects\MyJob\testcase\111.json 2020-11-04 16:41:49.754 | INFO | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2 2020-11-04 16:41:49.757 | INFO | httprunner.make:make_testcase:349 - start to make testcase: C:\Users\wwwww\PycharmProjects\MyJob\testcase\111.json 2020-11-04 16:41:49.760 | INFO | httprunner.make:make_testcase:442 - generated testcase: C:\Users\wwwww\PycharmProjects\MyJob\testcase\T111_test.py 2020-11-04 16:41:49.761 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ... d:\python\python37-32\lib\site-packages\urllib3\request.py:171: InvalidProxyConfigurationWarning: Your proxy configuration specified an HTTPS scheme for th e proxy. Are you sure you want to use HTTPS to contact the proxy? This most likely indicates an error in your configuration. Read this issue for more info: https://github.com/urllib3/urllib3/issues/1850 return self.urlopen(method, url, **extra_kw) reformatted C:\Users\wwwww\PycharmProjects\MyJob\testcase\T111_test.py All done! ✨ 🍰 ✨ 1 file reformatted. 2020-11-04 16:41:51.082 | INFO | httprunner.cli:main_run:56 - start to run tests with pytest. HttpRunner version: 3.1.4 ================================================================== test session starts =================================================================== platform win32 -- Python 3.7.4, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 rootdir: C:\Users\wwwww\PycharmProjects\MyJob\testcase plugins: html-2.1.1, metadata-1.10.0 collected 1 item T111_test.py . [100%] =================================================================== 1 passed in 0.34s ==================================================================== 2020-11-04 16:41:51.6142020-11-04 16:41:51.6592020-11-04 16:41:51.7012020-11-04 16:41:51.7022020-11-04 16:41:51.7032020-11-04 16:41:51.7052020-11-04 16:41: 51.7062020-11-04 16:41:51.7072020-11-04 16:41:51.7082020-11-04 16:41:51.7092020-11-04 16:41:51.710
生成报告
1.安装pytest-html
2.运行:hrun 111.json --html=../report/report.html;报告的生成路径为上级目录的report文件夹下。
需要增加响应断言
在111.json中增加断言,注意格式:content.+需要断言的字段