HttpRunner 参数化数据驱动

HttpRunner 2.0 参数化数据驱动案例,废话不说,直接上干货。

1、测试用例目录结构

     api:接口集

     testcases:测试用例

     testsuites:测试套件

     data:测试数据

      

2、api 接口集

 create1.yaml:

name: 创建外方
variables:
    -   customerName: 姓名
    -   customerGender: male
    -   customerBirth: 1998-09-09T00:00:00+0800
    -   resName: 姓名
request:
    method: POST
    url: $url/out_visits
    headers:
        Accept: application/json;charset=UTF-8
        Content-Type: application/json
    json:
        customerName: $customerName
        customerGender: $customerGender
        customerBirth: $customerBirth
        resName: $resName
extract:
    -   visitId: content.responseBody.id
validate:
    -   eq:
        -   status_code
        -   200
    -   eq:
        -   content.status
        -   $status
    -   eq:
        -   content.responseBody.resName
        -   $resName
    -   eq:
        -   content.responseBody.customerBirth
        -   $customerBirth

为了演示执行2个接口,在创建一个create2.yaml文件,代码与create1.yaml内容一样

3、testcases 测试用例

testcases_1.yaml:

- config:
    name: "创建外方1"
    id: 创建外方1

- test:
    name: 创建外方1_$msg
    api: api/create1.yaml

testcases_2.yaml:

- config:
    name: "创建外方2"
    id: 创建外方2

- test:
    name: 创建外方2_$msg
    api: api/create2.yaml 

 

4、testsuites 测试套件

testsuites_1.yaml:

config:
    name: "单接口测试testsuites"
testcases:
    create1:
        testcase: testcases/testcases_1.yaml
        parameters:
            resName-status-customerBirth-msg: ${P(data/account1.csv)}
    create2:
        testcase: testcases/testcases_2.yaml
        parameters:
            resName-status-customerBirth-msg: ${P(data/account2.csv)}

 

 5、data 测试数据

account1.csv:

resName,customerGender,status,customerBirth,msg
xingming,male,SUCCESS,1998-09-09T00:00:00+0800,create1_resName为字母
姓名,male,SUCCESS,1998-09-09T00:00:00+0800,create1_resName为汉字
姓名3,male,ERROR,1998-09-08T00:00:200+0800,create1_customerBirth日期格式不正确失败

 account2.csv:

resName,customerGender,status,customerBirth,msg
xingming,male,SUCCESS,1998-09-09T00:00:00+0800,create2_resName为字母
姓名,male,SUCCESS,1998-09-09T00:00:00+0800,create2_resName为汉字
姓名,male,ERROR,1998-09-08T00:00:200+0800,create2_customerBirth日期格式不正确失败

 

6、运行

# 执行用例
httprunner  --dot-env-path dev.env testsuites/testsuite_1.yaml

 

参考:https://cn.httprunner.org/advanced/parameters/

转载于:https://www.cnblogs.com/snailgirl/p/10309519.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值