场景一、添加公共配置

我们在做自动化开始的时候,一般有很多公共的环境配置,比如host、token、user等等,如果这些放在用例中,一旦修改,将非常的不便、麻烦(尤其切换环境)。

所以这里我们提供了apiConfig.yml 文件用于存放公共接口配置,默认会根据第一个接口数据包,解析保存 host header 的值,如果存在 cookie 调用也将自动保存。

你也可以根据自己的需要,手动添加其他公共配置,然后可以在测试用例yaml 或接口数据 json文件中使用。

apiConfig.yml

PyDemo:
  host: 10.88.88.88:30131
  headers:
    Content-Type: application/x-www-form-urlencoded
  cookies:
  headtoken: TESTxu5YwIZFkVGczMn0H0rot2ps7zRIbvrTOEKN
test_addOrUpCurBact.yaml
test_info:
  title: register
  host: ${host}
  scheme: http
  method: POST
  address: /api/register/addOrUpCurBact
  mime_type: application/x-www-form-urlencoded
  headers: ${headers}
  timeout: 10
  file: false
  cookies: false
  premise: /register/test_getAdultCurbactList.yaml
test_case:
- summary: addOrUpCurBact
  describe: test_addOrUpCurBact
  parameter: addOrUpCurBact_request.json
  check_body:
    check_type: check_json
    expected_code: 200
    expected_result:
      success: true
      msg: 返回成功
addOrUpCurBact_request.json
[
    {
        "summary": "addOrUpCurBact",
        "body": {
            "params": {
                "pageType": "0",
                "unitCode": "${unitCode}","materName": "狂犬病疫苗(vero细胞)",
                "inocCorpCode": "50",
                "speCodeName": "1.0ml",
                "vaccSpeCode": "1002",
                "pym": "kqbymveroxb",
                "price": "0",
                "batnmb": "20110101",
                "qty": "100","createDate": "",
                "createManCode": "${createManCode}","bactValidate": "$GenDate(y+1)",
                "bizType": 1,
                "materTypeCode": "1"
            },
            "headtoken": "${headtoken}"
        }
    }
]

 


场景二、设置动态参数值

 默认我们可以通过解析接口数据包,生成单条测试用例和测试脚本,但是有的时候我们希望接口入参是变动的,以便生成不同的测试数据,覆盖更多的测试情况。

这里我为大家提供了一些函数助手,用于生成不同的测试数据,详情参考如下:
test_info:
  title: register
  host: ${host}
  scheme: http
  method: POST
  address: /api/register/findParam
  mime_type: application/x-www-form-urlencoded
  headers: ${headers}
  timeout: 10
  file: false
  cookies: false
  premise: false
test_case:
- summary: findParam
  describe: test_findParam
  parameter:
    params:
      key01: '$RandInt(1,9)'        #生成1-9之间的随机数
      key02: '$RandStr(10)'       #生成10位随机字符
      key03: '$RandChoice(a,b,c,d)'  #从列表中随机选择
      key04: '$GenPhone()'         #生成一个伪手机号
      key05: '$GenGuid()'        #生成一个guid
      key06: '$GenWxid()'        #生成一个伪微信ID
      key07: '$GenNoid()'        #生成一个伪身份证
      key08: '$GenNoid(y-18)'     #生成一个18岁伪身份证
      key09: '$GenDate(m+1)'      #生成下个月今天的日期
      key10: '$GenDatetime(d-1)'   #生成昨天此时的时间
    headtoken: ${headtoken}
  check_body:
    check_type: check_json
    expected_code: 200
    expected_result:
      success: true
      code:
      msg: 返回成功
      data:
      - '1'
      - '1'
      callTime:

 运行日志:

PyDemo/testcase/register/test_findParam.py::TestRegister::test_findParam[case_data0] 2021-03-25 14:43:58,536 - apiSend.py - INFO: ====================================================================================================================
2021-03-25 14:43:58,536 - apiSend.py - INFO: 请求接口:findParam
2021-03-25 14:43:58,536 - apiSend.py - INFO: 请求地址:http://10.88.88.108:30131/api/register/findParam
2021-03-25 14:43:58,536 - apiSend.py - INFO: 请求头: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
2021-03-25 14:43:58,536 - apiSend.py - INFO: 请求参数: {'params': {
'key01': '6',
'key02': 'D7a5fBA8de',
'key03': 'd',
'key04': '15595173529',
'key05': '7A0C9736-8D35-11EB-94DD-005056C00008',
'key06': 'AUTOwZ5yhv1rag9tpKTC3oLFAkuO',
'key07': '228934202103259403',
'key08': '139059200303252386',
'key09': '2021-04-25',
'key10': '2021-03-24 14:43:58'
}, 'headtoken': 'xu5YwIZFkVGczMn0H0rot2ps7zRIbvrTHNwMXx1sJXg='} 2021-03-25 14:43:58,536 - apiSend.py - INFO: 请求方法: POST FAILED

 


场景三、添加多条用例

通常一个接口测试点会有多条,而默认只会生成一条,如果你想添加多条测试用例怎么办?

其实也很简单,只需要在 testcase 中参考第一条用例,添加多条用例即可,通过summary进行区分即可。

test_info:
  title: register
  host: ${host}
  scheme: http
  method: POST
  address: /api/register/findParam
  mime_type: application/x-www-form-urlencoded
  headers: ${headers}
  timeout: 10
  file: false
  cookies: false
  premise: false
test_case:
- summary: findParam
  describe: 测试点1
  parameter:
    params:
      unitCode: '3202112002'
      first: 0
      pym: ''
      pageSize: 10
      page: 0
    headtoken: ${headtoken}
  check_body:
    check_type: check_json
    expected_code: 200
    expected_result:
      success: true
      code:
      msg: 返回成功
      data:
      - '1'
      - '1'
      callTime:

- summary: findParam2
  describe: 测试点2
  parameter:
    params:
      unitCode: '3202112002'
      first: 1
      pym: ''
      pageSize: 1
      page: 10
    headtoken: ${headtoken}
  check_body:
    check_type: check_json
    expected_code: 200
    expected_result:
      success: true
      code:
      msg: 返回成功
      data:
      - '1'
      - '1'
      callTime:

运行日志:

C:\Python37\python.exe E:/__SVN__/Auto_Test_Jm/ApiTesting/startup.py
2021-03-18 10:50:59,642 - startup.py - INFO: 不开启自动生成测试用例功能,将直接运行测试!
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0 -- C:\Python37\python.exe
cachedir: .pytest_cache
rootdir: E:\__SVN__\Auto_Test_Jm\ApiTesting
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collecting ... collected 6 items / 4 deselected / 2 selected

PyDemo/testcase/register/test_findParam.py::TestRegister::test_findParam[case_data0] 2021-03-18 10:50:59,987 - apiSend.py - INFO: ===================================================================================================================
2021-03-18 10:50:59,987 - apiSend.py - INFO: 请求接口:findParam
2021-03-18 10:50:59,987 - apiSend.py - INFO: 请求地址:http://10.88.88.141:20037/api/register/findParam
2021-03-18 10:50:59,987 - apiSend.py - INFO: 请求头: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
2021-03-18 10:50:59,987 - apiSend.py - INFO: 请求参数: {'params': {'unitCode': '3202112002', 'first': 0, 'pym': '', 'pageSize': 10, 'page': 0}, 'headtoken': 'xu5YwIZFkVGczMn0H0rot2ps7zRIbvrTHNwMXx1sJXg='}
2021-03-18 10:50:59,987 - apiSend.py - INFO: 请求方法: POST
2021-03-18 10:51:00,003 - apiSend.py - INFO: 请求接口结果:
 (200, {'success': True, 'code': None, 'msg': '返回成功', 'data': ['1', '1'], 'callTime': None})
PASSED
PyDemo/testcase/register/test_findParam.py::TestRegister::test_findParam[case_data1] 2021-03-18 10:51:01,022 - apiSend.py - INFO: ===================================================================================================================
2021-03-18 10:51:01,022 - apiSend.py - INFO: 请求接口:findParam2
2021-03-18 10:51:01,022 - apiSend.py - INFO: 请求地址:http://10.88.88.141:20037/api/register/findParam
2021-03-18 10:51:01,022 - apiSend.py - INFO: 请求头: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
2021-03-18 10:51:01,022 - apiSend.py - INFO: 请求参数: {'params': {'unitCode': '3202112002', 'first': 1, 'pym': '', 'pageSize': 1, 'page': 10}, 'headtoken': 'xu5YwIZFkVGczMn0H0rot2ps7zRIbvrTHNwMXx1sJXg='}
2021-03-18 10:51:01,022 - apiSend.py - INFO: 请求方法: POST
2021-03-18 10:51:01,038 - apiSend.py - INFO: 请求接口结果:
 (200, {'success': True, 'code': None, 'msg': '返回成功', 'data': ['1', '1'], 'callTime': None})
PASSED

======================= 2 passed, 4 deselected in 2.26s =======================
Report successfully generated to E:\__SVN__\Auto_Test_Jm\ApiTesting\PyDemo\report

如果是参数单独存放在json文件中的,同样可参考第一条,添加多个(json文件是以列表形式存储的),依然通过summary进行区分。

[
    {
        "summary": "addOrUpCurBact",
        "body": {
            "params": {
                "pageType": "0",
                "unitCode": "${unitCode}","materName": "狂犬病疫苗(vero细胞)",
                "inocCorpCode": "50",
                "speCodeName": "1.0ml",
                "vaccSpeCode": "1002",
                "pym": "kqbymveroxb",
                "price": "0",
                "batnmb": "20110101","dataType": 2,
                "createDate": "",
                "createManCode": "${createManCode}","bactValidate": "$GenDate(y+1)",
                "bizType": 1,
                "materTypeCode": "1"
            },
            "headtoken": "${headtoken}"
        }
    },
    {
        "summary": "addOrUpCurBact2",
        "body": {
            "params": {
                "pageType": "0",
                "unitCode": "${unitCode}","materName": "狂犬球蛋白",
                "inocCorpCode": "50",
                "speCodeName": "0.5ml",
                "vaccSpeCode": "1005",
                "pym": "kqqdb",
                "price": "0",
                "batnmb": "20220202","dataType": 2,
                "createDate": "",
                "createManCode": "${createManCode}","bactValidate": "2022-02-02",
                "bizType": 1,
                "materTypeCode": "1"
            },
            "headtoken": "${headtoken}"
        }
    }
]
 

 


场景四、手动编写用例

 如果你不想抓取接口数据包,也可以根据以下模板,手动编写测试用例,然后运行auto_switch=1,系统也会自动生成对应的测试脚本,。

# 用例基本信息
test_info:
  # 测试用例标题,默认截取请求地址倒数第2个字段名,在报告中作为一级目录显示
  title: register
  # 请求域名,默认读取公共关联值,可修改
  host: ${host}
  # 请求协议
  scheme: http
  # 请求类型
  method: POST
  # 请求地址
  address: /api/register/findParam
  # 参数媒体类型
  mime_type: application/x-www-form-urlencoded
  # 请求头,默认读取公共关联值,可修改
  headers: ${headers}
  # 超时时长(s)
  timeout: 10
  # 是否需要上传文件
  file: false
  # 是否需要获取cookie
  cookies: false
  # 是否存在前置接口,如果存在,则填写前置接口用例相对路径,如:/register/test_getAdultCurbactList.yaml
  premise: false

# 测试用例,默认仅生成一个,可手动添加多个
test_case:
  # 用例概要,默认截取请求地址倒数第1个字段名
- summary: findParam
  # 用例描述,在报告中作为二级目录显示
  describe: test_findParam
  # 接口请求参数,当总字符数超过200,将转为json文件单独存储
  parameter:
    params:
      unitCode: '3202112002'
      first: 0
      pym: ''
      pageSize: 10
      page: 0
    headtoken: ${headtoken}
  # 接口检查结果
  check_body:
    # 检查类型,目前支持5种,可自行修改,默认check_json,即仅检查实际与期望结果格式是否一致
    check_type: check_json
    # 期望接口返回码
    expected_code: 200
    # 期望接口返回消息体,当总字符数超过200,将转为json文件单独存储
    expected_result:
      success: true
      code:
      msg: 返回成功
      data:
      - '1'
      - '1'
      callTime:

 


场景五、多条接口关联

 很多时候我们的接口都是有关联的,只有调用了前一个接口后才能调用后一个接口,此时我们就可以通过 premise 参数传入前一个接口的相对路径即可。

 ApiTesting全链路接口自动化测试框架 - 实战应用-LMLPHP

通过以下日志不难发现,在调用 addOrUpCurBact 接口前自动调用了 getAdultCurbactList 接口。

当然,如果在调用 getAdultCurbactList 接口之前还需要调用其他接口,同样在 getAdultCurbactList 接口中添加前一个接口相对路径即可。

:\Python37\python.exe E:/__SVN__/Auto_Test_Jm/ApiTesting/startup.py
2021-03-18 09:15:18,574 - startup.py - INFO: 不开启自动生成测试用例功能,将直接运行测试!
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0 -- C:\Python37\python.exe
cachedir: .pytest_cache
rootdir: E:\__SVN__\Auto_Test_Jm\ApiTesting
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collecting ... collected 5 items / 4 deselected / 1 selected

PyDemo/testcase/register/test_addOrUpCurBact.py::TestRegister::test_addOrUpCurBact[case_data0] 2021-03-18 09:15:18,886 - initializePremise.py - INFO: 获取前置接口测试用例:/register/test_getAdultCurbactList.yaml
2021-03-18 09:15:18,886 - initializePremise.py - INFO: 执行前置接口测试用例:{'title': 'register', 'host': '10.88.88.141:20037', 'scheme': 'http', 'method': 'POST', 'address': '/api/register/getAdultCurbactList', 'mime_type': 'application/x-www-form-urlencoded', 'headers': {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}, 'timeout': 10, 'file': False, 'cookies': False, 'premise': False}
2021-03-18 09:15:18,886 - apiSend.py - INFO: ======================================================================================================================================================
2021-03-18 09:15:18,886 - apiSend.py - INFO: 请求接口:getAdultCurbactList
2021-03-18 09:15:18,886 - apiSend.py - INFO: 请求地址:http://10.88.88.141:20037/api/register/getAdultCurbactList
2021-03-18 09:15:18,886 - apiSend.py - INFO: 请求头: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
2021-03-18 09:15:18,886 - apiSend.py - INFO: 请求参数: {'params': {'unitCode': '3202112002', 'first': 0, 'pym': '', 'pageSize': 10, 'page': 0}, 'headtoken': 'xu5YwIZFkVGczMn0H0rot2ps7zRIbvrTHNwMXx1sJXg='}
2021-03-18 09:15:18,886 - apiSend.py - INFO: 请求方法: POST
2021-03-18 09:15:18,933 - apiSend.py - INFO: 请求接口结果:
 (200, {'success': True, 'code': None, 'msg': '返回成功', 'data': {'totalPage': 4, 'list': [{'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 1, 'coreName': '大连雅立峰', 'corpSimpName': '大连雅立峰', 'createDate': '2021-02-23 16:02:45', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': '06F2F6DA-2EF8-F372-E37B-E99AB6CE9917', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '狂犬病疫苗(vero细胞)', 'materType': '86901119000052', 'materTypeCode': '1', 'modifyDate': '2021-03-09 14:32:29', 'modifyManCode': '3202112002013', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒5支', 'pageSize': None, 'pageType': None, 'price': 0, 'priceEditMode': None, 'pym': 'kqbymveroxb', 'qty': 9831, 'speCode': None, 'speCodeName': '1.0ml', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1002'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 1, 'coreName': '武汉生物', 'corpSimpName': '武汉生物', 'createDate': '2021-02-23 16:02:46', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': '769BD77C-43AB-3A2B-6383-6F5F6EC584AA', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '狂犬球蛋白', 'materType': '86901960000553', 'materTypeCode': '2', 'modifyDate': '2021-03-05 15:56:37', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 0, 'priceEditMode': None, 'pym': 'kqqdb', 'qty': 9873, 'speCode': None, 'speCodeName': '200IU', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1020'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 2, 'coreName': '成都欧林', 'corpSimpName': '成都欧林', 'createDate': '2021-02-23 16:02:47', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': 'B54ADF57-26AA-E75D-8AA0-803BD15D89F8', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '破伤风疫苗', 'materType': '86981089000016', 'materTypeCode': '1', 'modifyDate': '2021-03-05 15:56:46', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 20, 'priceEditMode': None, 'pym': 'psfym', 'qty': 9954, 'speCode': None, 'speCodeName': '0.5ml', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1001'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 2, 'coreName': '华兰生物工程重庆', 'corpSimpName': '华兰生物工程重庆', 'createDate': '2021-02-23 16:02:48', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': 'CCB456B8-65F5-01B0-A049-9558CC985F94', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '破伤风球蛋白', 'materType': '86909588000054', 'materTypeCode': '2', 'modifyDate': '2021-03-05 15:56:50', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 20, 'priceEditMode': None, 'pym': 'psfqdb', 'qty': 9925, 'speCode': None, 'speCodeName': '250IU', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1021'}]}, 'callTime': None})
2021-03-18 09:15:19,962 - apiSend.py - INFO: ======================================================================================================================================================
2021-03-18 09:15:19,962 - apiSend.py - INFO: 请求接口:addOrUpCurBact
2021-03-18 09:15:19,962 - apiSend.py - INFO: 请求地址:http://10.88.88.141:20037/api/register/addOrUpCurBact
2021-03-18 09:15:19,962 - apiSend.py - INFO: 请求头: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'}
2021-03-18 09:15:19,962 - apiSend.py - INFO: 请求参数: {'params': {'pageType': '0', 'unitCode': '3202112002', 'bactCode': '280101', 'materType': '86901119000052', 'coreName': '大连雅立峰', 'corpSimpName': '大连雅立峰', 'materName': '狂犬病疫苗(vero细胞)', 'inocCorpCode': '50', 'speCodeName': '1.0ml', 'vaccSpeCode': '1002', 'pym': 'kqbymveroxb', 'price': '0', 'batnmb': '20110101', 'qty': '100', 'ifUse': 1, 'dataType': 2, 'createDate': '', 'createManCode': '3202112002008', 'modifyDate': '', 'modifyManCode': '3202112002008', 'bactValidate': '2022-03-18', 'bizType': 1, 'materTypeCode': '1'}, 'headtoken': 'xu5YwIZFkVGczMn0H0rot2ps7zRIbvrTHNwMXx1sJXg=', 'data': {'success': True, 'code': None, 'msg': '返回成功', 'data': {'totalPage': 4, 'list': [{'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 1, 'coreName': '大连雅立峰', 'corpSimpName': '大连雅立峰', 'createDate': '2021-02-23 16:02:45', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': '06F2F6DA-2EF8-F372-E37B-E99AB6CE9917', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '狂犬病疫苗(vero细胞)', 'materType': '86901119000052', 'materTypeCode': '1', 'modifyDate': '2021-03-09 14:32:29', 'modifyManCode': '3202112002013', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒5支', 'pageSize': None, 'pageType': None, 'price': 0, 'priceEditMode': None, 'pym': 'kqbymveroxb', 'qty': 9831, 'speCode': None, 'speCodeName': '1.0ml', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1002'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 1, 'coreName': '武汉生物', 'corpSimpName': '武汉生物', 'createDate': '2021-02-23 16:02:46', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': '769BD77C-43AB-3A2B-6383-6F5F6EC584AA', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '狂犬球蛋白', 'materType': '86901960000553', 'materTypeCode': '2', 'modifyDate': '2021-03-05 15:56:37', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 0, 'priceEditMode': None, 'pym': 'kqqdb', 'qty': 9873, 'speCode': None, 'speCodeName': '200IU', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1020'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 2, 'coreName': '成都欧林', 'corpSimpName': '成都欧林', 'createDate': '2021-02-23 16:02:47', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': 'B54ADF57-26AA-E75D-8AA0-803BD15D89F8', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '破伤风疫苗', 'materType': '86981089000016', 'materTypeCode': '1', 'modifyDate': '2021-03-05 15:56:46', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 20, 'priceEditMode': None, 'pym': 'psfym', 'qty': 9954, 'speCode': None, 'speCodeName': '0.5ml', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1001'}, {'bactCode': None, 'bactValidate': '2022-02-02 00:00:00', 'bacttypeGroupcode': None, 'batnmb': '20220202', 'bizType': 2, 'coreName': '华兰生物工程重庆', 'corpSimpName': '华兰生物工程重庆', 'createDate': '2021-02-23 16:02:48', 'createManCode': '3202112002008', 'createManName': None, 'createUnitcode': '3202112002', 'dataType': 2, 'delTime': None, 'first': None, 'guid': 'CCB456B8-65F5-01B0-A049-9558CC985F94', 'ifAdd': None, 'ifMulti': 0, 'ifUse': 1, 'inocCorpCode': None, 'materName': '破伤风球蛋白', 'materType': '86909588000054', 'materTypeCode': '2', 'modifyDate': '2021-03-05 15:56:50', 'modifyManCode': '3202112002008', 'modifyManName': None, 'modifyUnitcode': '3202112002', 'modifytDate': None, 'packageNum': '盒1支', 'pageSize': None, 'pageType': None, 'price': 20, 'priceEditMode': None, 'pym': 'psfqdb', 'qty': 9925, 'speCode': None, 'speCodeName': '250IU', 'stopDate': None, 'storageCode': None, 'storageGuid': None, 'storageName': None, 'synDataList': [], 'unitCode': '3202112002', 'vaccSpeCode': '1021'}]}, 'callTime': None}}
2021-03-18 09:15:19,978 - apiSend.py - INFO: 请求方法: POST
2021-03-18 09:15:20,009 - apiSend.py - INFO: 请求接口结果:
 (200, {'success': True, 'code': None, 'msg': '返回成功', 'data': None, 'callTime': None})
PASSED

======================= 1 passed, 4 deselected in 2.32s =======================
Report successfully generated to E:\__SVN__\Auto_Test_Jm\ApiTesting\PyDemo\report\html

Process finished with exit code 0
 
再如果,你还需要获取到前一个接口返回的参数值,那你只需要使用 ${key} 格式,这里的key是前一个接口返回的参数。就比如以下 ${msg},这里系统将获取上一个接口的msg返回值作为当前值。
test_case:
- summary: addOrUpCurBact
  describe: test_addOrUpCurBact
  parameter: addOrUpCurBact_request.json
  check_body:
    check_type: check_json
    expected_code: 200
    expected_result:
      success: true
      code:
      msg: ${msg}
      data:
      callTime:
03-25 17:53