HttpRunner用例生成

HttpRunner用例生成

1.测试数据抓包
     在开始测试之前,我们需要先了解接口的请求和响应细节,而最佳的方式就是采用 Charles Proxy 或者 Fiddler 这类网络抓包工具进行抓包分析(我个人强推Charles
    示例: 以某快递查询接口为例,在本案例中,我们先进行权限校验,然后成功创建一个用户
    相应参数如下:
{"message":"ok","nu":"350757819118","ischeck":"1","condition":"F00","com":"huitongkuaidi","status":"200","state":"3","data":[{"time":"2017-12-21 15:42:29","ftime":"2017-12-21 15:42:29","context":"广州市|广州市【广州新永和站】,周祥代 已签收","location":""},{"time":"2017-12-21 14:28:59","ftime":"2017-12-21 14:28:59","context":"广州市|广州市【广州新永和站】,【周海祥/18925068779】正在派件","location":""},{"time":"2017-12-21 14:27:59","ftime":"2017-12-21 14:27:59","context":"广州市|到广州市【广州新永和站】","location":""},{"time":"2017-12-20 23:43:30","ftime":"2017-12-20 23:43:30","context":"广州市|广州市【广州黄埔转运中心】,正发往【广州新永和站】","location":""},{"time":"2017-12-20 20:40:15","ftime":"2017-12-20 20:40:15","context":"广州市|到广州市【广州黄埔转运中心】","location":""},{"time":"2017-12-20 16:18:35","ftime":"2017-12-20 16:18:35","context":"广州市|广州市【广州转运中心】,正发往【广州黄埔转运中心】","location":""},{"time":"2017-12-20 08:27:05","ftime":"2017-12-20 08:27:05","context":"广州市|到广州市【广州转运中心】","location":""},{"time":"2017-12-19 03:21:02","ftime":"2017-12-19 03:21:02","context":"西安市|西安市【西安转运中心】,正发往【广州转运中心】","location":""},{"time":"2017-12-18 22:52:37","ftime":"2017-12-18 22:52:37","context":"西安市|到西安市【西安转运中心】","location":""},{"time":"2017-12-18 22:43:29","ftime":"2017-12-18 22:43:29","context":"西安市|到西安市【西安南郊二站集货点】","location":""},{"time":"2017-12-17 21:29:25","ftime":"2017-12-17 21:29:25","context":"西安市|西安市【西安西郊五站】,【赵永刚/02962255063】已揽收","location":""}]}

2.用Charles工具录制
Charles工具录制结果:


右键导出,选择har格式



3. 将har文件进行转换
cmd命令:
>>>  har2case kauidi.har  kuaidi.json
>>>  har2case kauidi.har  kuaidi.yml 【准换成YAML格式用例】
这样就可以把har格式的转换为json格式的用例
切换之前最好把目录切换到har文件所在的目录

转换成功后,会在同文件夹生成一个json文件(如图所示)




生成的.json文件内容如下:
[
    {
        "config": {
            "name": "testset description",
            "variables": [],
            "request": {
                "base_url": "",
                "headers": {
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
                }
            }
        }
    },
    {
        "test": {
            "name": "/query",
            "request": {
                "params": {
                    "type": "huitongkuaidi",
                    "postid": "350757819118"
                },
                "url": "http://www.kuaidi100.com/query",
                "method": "GET"
            },
            "validate": [
                {
                    "eq": [
                        "status_code",
                        200
                    ]
                },
                {
                    "eq": [
                        "headers.Content-Type",
                        "text/html;charset=UTF-8"
                    ]
                }
            ]
        }
    }
]


  测试用例的格式如下:
 

    config:作为整个测试用例集的全局配置项
    test:对应单个测试用例

猜你喜欢

转载自blog.csdn.net/lykio_881210/article/details/79788914