Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
/ har2case Public archive

Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner. Merged to httprunner/ext/har2case.

License

Notifications You must be signed in to change notification settings

httprunner/har2case

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Convert HAR(HTTP Archive) to YAML/JSON testcases for HttpRunner. Merged to httprunner/ext/har2case.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages