Skip to main content

har2case

LICENSE travis-ci coveralls pypi version pyversions

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
                    ]
                }
            ]
        }
    }
]

Release files for har2case 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for har2case 0.3.1
File Size Uploaded
har2case-0.3.1.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for har2case 0.3.1
File Interpreter ABI Platform
har2case-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 26.8 kB

Release files / har2case-0.3.1.tar.gz

Download URL har2case-0.3.1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8f159ec7cba82ec4282f46af4a9dac89f65e62796521b2426d3c89c3c9fd8579
BLAKE2b-256 checksum
How to use checksums
6beeb8aaee386178d80549472cf02889be6851729e7cc7ba804fff1f5f165dc7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / har2case-0.3.1-py2.py3-none-any.whl

Download URL har2case-0.3.1-py2.py3-none-any.whl
Size 15.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
84d3a5cc9fbb16e45372e7e880a936c59bbe8e9b66bad81927769e64f608e2af
BLAKE2b-256 checksum
How to use checksums
353a9c3093d9661622bb8e455321bb074e32811072b900e2d93272da8e239157
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.10

1 release file

0.1.9

1 release file

0.1.8

2 release files

0.1.7.4

1 release file

0.1.7.1

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page