Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner.
Project description
har2case
Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner.
install
har2case
is available on PyPI
and can be installed through pip.
$ pip install har2case
usage
When har2case
is installed, a har2case command 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 see har2case
version:
$ har2case -V
0.2.1
To 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 '|'
examples
In most cases, you can only specify har source file path. By default, har2case
will generate testcase file in JSON format.
$ har2case tests/data/demo.har
INFO:root:Start to generate testcase.
INFO:root:dump testcase to JSON format.
INFO:root:Generate JSON testcase successfully: tests/data/demo.json
If you want to generate testcase file in YAML format, you can add -2y
or --to-yml
argument.
$ har2case tests/data/demo.har -2y
INFO:root:Start to generate testcase.
INFO:root:dump testcase to YAML format.
INFO:root:Generate YAML testcase successfully: tests/data/demo.yaml
The generated testcase file is in the same folder with the har source file and has the same name.
filter
You can do some filter while conversion, only url that includes filter string will be converted.
$ har2case tests/data/demo.har --filter httprunner.org
exclude
You can also set exclude keyword while conversion, url that includes exclude string will be ignored.
$ har2case tests/data/demo.har --exclude debugtalk.com
generated testcase
Generated YAML testcase demo.yml
shows like below:
- config:
name: testcase description
variables: {}
- test:
name: /api/v1/Account/Login
request:
headers:
Content-Type: application/json
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
json:
Pwd: '123'
UserName: test001
VerCode: ''
method: POST
url: https://httprunner.org/api/v1/Account/Login
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
And generated JSON testcase demo.json
shows 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
]
}
]
}
}
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file har2case-0.3.1.tar.gz
.
File metadata
- Download URL: har2case-0.3.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f159ec7cba82ec4282f46af4a9dac89f65e62796521b2426d3c89c3c9fd8579 |
|
MD5 | 383c20fe66d92c995076c16d151c0288 |
|
BLAKE2b-256 | 6beeb8aaee386178d80549472cf02889be6851729e7cc7ba804fff1f5f165dc7 |
File details
Details for the file har2case-0.3.1-py2.py3-none-any.whl
.
File metadata
- Download URL: har2case-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84d3a5cc9fbb16e45372e7e880a936c59bbe8e9b66bad81927769e64f608e2af |
|
MD5 | 1f5a61d476a26faf2c7eb8d1961f3b47 |
|
BLAKE2b-256 | 353a9c3093d9661622bb8e455321bb074e32811072b900e2d93272da8e239157 |