–
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 |