Skip to main content

fork from https://github.com/HttpRunner/har2case. Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

har2case2-0.3.5.tar.gz (15.9 kB view details)

Uploaded Source

File details

Details for the file har2case2-0.3.5.tar.gz.

File metadata

  • Download URL: har2case2-0.3.5.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for har2case2-0.3.5.tar.gz
Algorithm Hash digest
SHA256 d7ac27a0c7b1bc23c2ba3a5d1e40163ad28c0fa9f7d10307a8cd8a34412e2e32
MD5 c6d9d0eb08a37b3bc24bffb9454c890a
BLAKE2b-256 31d19e263c86f6e892066cce82325aa71e6f51075e591927de2b2c10ffeeba0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page