Package: har2case2
har2caseConvert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner.installhar2caseis available onPyPIand can be installed through pip.$pipinstallhar2caseusageWhenhar2caseis installed, ahar2casecommand should be available in your shell (if you're not using
virtualenv—which you should—make sure your python script directory is on your path).To seehar2caseversion:$har2case-V0.2.1To see available options, run:$ har2case -h
usage: main.py [-h] [-V] [--log-level LOG_LEVEL] [-2y] [--filter FILTER]
               [--exclude EXCLUDE]
               [har_source_file]

Convert HAR to YAML/JSON testcases for HttpRunner.

positional arguments:
  har_source_file       Specify HAR source file

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show version
  --log-level LOG_LEVEL
                        Specify logging level, default is INFO.
  -2y, --to-yml, --to-yaml
                        Convert to YAML format, if not specified, convert to
                        JSON 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 '|'examplesIn most cases, you can only specify har source file path. By default,har2casewill generate testcase file in JSON format.$har2casetests/data/demo.har
INFO:root:Starttogeneratetestcase.
INFO:root:dumptestcasetoJSONformat.
INFO:root:GenerateJSONtestcasesuccessfully:tests/data/demo.jsonIf you want to generate testcase file in YAML format, you can add-2yor--to-ymlargument.$har2casetests/data/demo.har-2y
INFO:root:Starttogeneratetestcase.
INFO:root:dumptestcasetoYAMLformat.
INFO:root:GenerateYAMLtestcasesuccessfully:tests/data/demo.yamlThe generated testcase file is in the same folder with the har source file and has the same name.filterYou can do some filter while conversion, only url that includes filter string will be converted.$har2casetests/data/demo.har--filterhttprunner.orgexcludeYou can also set exclude keyword while conversion, url that includes exclude string will be ignored.$har2casetests/data/demo.har--excludedebugtalk.comgenerated testcaseGenerated YAML testcasedemo.ymlshows like below:-config:name:testcase descriptionvariables:{}-test:name:/api/v1/Account/Loginrequest:headers:Content-Type:application/jsonUser-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36(KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36json:Pwd:'123'UserName:test001VerCode:''method:POSTurl:https://httprunner.org/api/v1/Account/Loginvalidate:-eq:-status_code-200-eq:-headers.Content-Type-application/json; charset=utf-8-eq:-content.IsSuccess-true-eq:-content.Code-200-eq:-content.Message-nullAnd generated JSON testcasedemo.jsonshows like this:[{"config":{"name":"testcase description","variables":{}}},{"test":{"name":"/api/v1/Account/Login","request":{"url":"https://httprunner.org/api/v1/Account/Login","method":"POST","headers":{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36","Content-Type":"application/json"},"json":{"UserName":"test001","Pwd":"123","VerCode":""}},"validate":[{"eq":["status_code",200]},{"eq":["headers.Content-Type","application/json; charset=utf-8"]},{"eq":["content.IsSuccess",true]},{"eq":["content.Code",200]},{"eq":["content.Message",null]}]}}]