将har(http存档)转换为httprunner的yaml/json测试用例。

har2case的Python项目详细描述


har2case

LICENSEtravis-cicoverallspypi versionpyversions

将har(http存档)转换为httprunner的yaml/json测试用例。

安装

har2casePyPI上可用,可以通过pip安装。

$ pip install har2case

用法

安装har2case时,shell中应该有一个har2case命令(如果不使用 您应该确保python脚本目录在您的路径上。

查看har2case版本:

$ har2case -V
0.2.1

要查看可用选项,请运行:

$ 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 '|'

示例

在大多数情况下,只能指定har源文件路径。默认情况下,har2case将生成json格式的测试用例文件。

$ 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

如果要生成yaml格式的testcase文件,可以添加-2y--to-yml参数。

$ 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

生成的testcase文件与har源文件位于同一文件夹中,并且具有相同的名称。

filter

转换时可以进行一些筛选,只有包含筛选字符串的url才会被转换。

$ har2case tests/data/demo.har --filter httprunner.org

排除

您也可以在转换时设置exclude关键字,包含exclude字符串的url将被忽略。

$ har2case tests/data/demo.har --exclude debugtalk.com

生成的测试用例

生成的yaml测试用例demo.yml如下所示:

-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-null

生成的json测试用例demo.json显示如下:

[{"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]}]}}]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用MongoDB进行java漏斗分析?   java如何重构此代码以仅执行一次方法logViolation(),并在单个字符串中获取字符串变量(speedType)的所有值   java如何将方向向量转换为角度?   Java中json文件中的股票价格   java有没有一种方法可以查看网站中的哪些资源加载了selenium?   java文件定位器可以指向不同文件服务器上的目录吗?   java GWT等待SetVisibleRange和ClearData完成   macos Java Applet无法在Mac OS下接收鼠标输入   java BottomNavigationView不支持单次单击必须单击两次   MS SQL Server 2012中的java:我的数据库名称是J.3.0.0\u DEV我无法在Oracle SQL Developer IDE中连接它?   java对JFileChooser的修改,只显示文件夹内容   java如何将动态对象查询更改为criteria builder或更好的性能   java中的swing新字体类型   java Hibernate。删除未使用的条目   上载CSV文件并将其转换为Java模型对象   java如何将信息添加到库的日志消息中?   JavaEclipseGit:使用egit从另一个分支、标记或引用打开版本   使用Firebase控制台消息的java开放视频