httprunner3.x .har文件处理运行

本文介绍了如何利用HAR文件(来自Charles或Fiddler)转换为YAML/JSON格式,用于HttpRunner测试用例。通过`har2case`工具将.HAR转换为.YAML或.JSON,并将其放置在testcases文件夹中,然后使用`hrun`命令运行。需要注意,转换后的文件需手动调整为符合HttpRunner识别的格式。文中还提示可参考testcases文件夹中的模板文件进行修改。
摘要由CSDN通过智能技术生成

httprunner中引用的是yaml/json写测试用例,但是有些时候一个一个的写比较繁琐,为了减少繁琐事务,应用.har文件转成yaml/json文件运行测试用例。

项目工程目录:
在这里插入图片描述
har中的文件可以直接从Charles或者Fiddler中抓取后导出放到har文件夹中:
在这里插入图片描述在这里插入图片描述
har文件夹中的.har文件我们要转成yaml/json文件,具体命令我们可以使用帮助命令查看下 har2case -h:

F:\TESTING\apiWebStudent\demo>har2case -h
usage: har2case har2case [-h] [-2y] [-2j] [--filter FILTER]
                         [--exclude EXCLUDE]
                         [har_source_file]

positional arguments:
  har_source_file       Specify HAR source file

optional arguments:
  -h, --help            show this help message and exit
  -2y, --to-yml, --to-yaml
                        Convert to YAML format, if not specified, convert to
                        pytest format by default.
  -2j, --to-json        Convert to JSON format, if not specified, convert to
                        pytest format by default.
  --filter FILTER       Specify filter keyword, only url include filter string
                        will be converted.
  --exclude EXCLUDE     Specify exclude keyword, url that includes exclude
                        string will be ignored, multiple keywords can be
                        joined with '|'

  • 转成yaml文件 har2case xxx.har -2y:
F:\TESTING\apiWebStudent\demo\har>har2case studentLogin.har -2y
2021-03-23 18:26:24.084 | INFO     | httprunner.ext.har2case.core:gen_testcase:356 - Start to generate testcase from F:\TESTING\apiWebStudent\demo\har\studentLogin.har
2021-03-23 18:26:24.085 | INFO     | httprunner.ext.har2case.core:_make_testcase:347 - Extract info from HAR file and prepare for testcase.
2021-03-23 18:26:24.168 | INFO     | httprunner.ext.har2case.utils:dump_yaml:108 - dump testcase to YAML format.
2021-03-23 18:26:24.301 | INFO     | httprunner.ext.har2case.utils:dump_yaml:115 - Generate YAML testcase successfully: F:\TESTING\apiWebStudent\demo\har\studentLogin.yml
2021-03-23 18:26:24.303 | INFO     | httprunner.ext.har2case.core:gen_testcase:377 - generated testcase: F:\TESTING\apiWebStudent\demo\har\studentLogin.yml
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-Break to quit

  • 转成json文件 har2case xxx.har -2j
F:\TESTING\apiWebStudent\demo\har>har2case studentLogin.har -2j
2021-03-23 18:27:09.102 | INFO     | httprunner.ext.har2case.core:gen_testcase:356 - Start to generate testcase from F:\TESTING\apiWebStudent\demo\har\studentLogin.har
2021-03-23 18:27:09.104 | INFO     | httprunner.ext.har2case.core:_make_testcase:347 - Extract info from HAR file and prepare for testcase.
2021-03-23 18:27:09.192 | INFO     | httprunner.ext.har2case.utils:dump_json:121 - dump testcase to JSON format.
2021-03-23 18:27:09.198 | INFO     | httprunner.ext.har2case.utils:dump_json:130 - Generate JSON testcase successfully: F:\TESTING\apiWebStudent\demo\har\studentLogin.json
2021-03-23 18:27:09.199 | INFO     | httprunner.ext.har2case.core:gen_testcase:377 - generated testcase: F:\TESTING\apiWebStudent\demo\har\studentLogin.json
Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-Break to quit

在这里插入图片描述
把har文件夹中转成的json/yaml文件移动到testcases文件夹中,然后运行 hrun xxxx 运行:

F:\TESTING\apiWebStudent\demo>hrun testcases
2021-03-23 18:43:24.012 | INFO     | httprunner.make:__make:512 - make path: F:\TESTING\apiWebStudent\demo\testcases
2021-03-23 18:43:24.019 | INFO     | httprunner.compat:ensure_testcase_v3:219 - ensure compatibility with testcase format v2
2021-03-23 18:43:24.025 | INFO     |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值