httprunner小试

安装httprunner第三方库

pip install httprunner

安装har2case

pip install har2case

httprunner小试

 

 

 查看是否安装成功

httprunner小试

 

 

 抓包工具抓取接口并导出,导出格式必须为har

httprunner小试

 

 使用har2case命令,将har格式的接口文件转换成测试用例

默认转换成json

命令:har2case 111.har

 httprunner小试

 

转换成yml格式的文件

命令:har2case 111.har -2y

httprunner小试

 

 

 

运行测试

第一种:使用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

 

httprunner小试

上一篇:POSIX 可移植操作系统接口


下一篇:【重学前端】JS基础-原型和原型链