场景一、添加公共配置

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

所以这里我们提供了apiConfig.yml 文件用于存放公共接口配置,默认会根据第一个接口数据包,解析保存 hostheader 的值,如果存在 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

其中 $GenNoid()、$GenDate()、$Gendatetime() 方法默认获取当前日期时间,同时支日期标识[ 年y,月m,日d,时h,分M,秒s ]标识搭配 [ +, - ]和数字,用于对日期时间进行调整。


场景三、添加多条用例

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

其实也很简单,只需要在 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 参数传入前一个接口的相对路径即可。

通过以下日志不难发现,在调用 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:

作者:Leozhanggg

出处:https://www.cnblogs.com/leozhanggg/p/14519800.html

源码:https://github.com/Leozhanggg/ApiTesting

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

ApiTesting全链路接口自动化测试框架 - 实战应用的更多相关文章

  1. ApiTesting全链路接口自动化测试框架 - 新增数据库校验(二)

    在这之前我完成了对于接口上的自动化测试:ApiTesting全链路接口自动化测试框架 - 初版(一) 但是对于很多公司而言,数据库的数据校验也尤为重要,另外也有小伙伴给我反馈希望支持. 所以最近几天我 ...

  2. Python接口自动化测试框架实战 从设计到开发

    第1章 课程介绍(不要错过)本章主要讲解课程的详细安排.课程学习要求.课程面向用户等,让大家很直观的对课程有整体认知! 第2章 接口测试工具Fiddler的运用本章重点讲解如何抓app\web的htt ...

  3. ApiTesting全链路自动化测试框架 - 初版发布(一)

    简介 此框架是基于Python+Pytest+Requests+Allure+Yaml+Json实现全链路接口自动化测试. 主要流程:解析接口数据包 ->生成接口基础配置(yml) ->生 ...

  4. 性能测试学习之路 (四)jmeter 脚本开发实战(JDBC &JMS &接口脚本 & 轻量级接口自动化测试框架)

    1.业务级脚本开发 登录脚本->思路:在线程组下新建两个HTTP请求,一个是完成访问登录页,一个是完成登录的数据提交.   步骤如下: 1) 访问登录页 2) 提交登录数据的HTTP PS:对于 ...

  5. 接口自动化测试框架【windows版】:jmeter + ant + jenkins

    为了提高回归效率及保证版本质量,很多公司都在做自动化测试,特别是接口自动化.接口自动化测试框架很多,有写代码的,也有不写代码的,我觉得没有谁比谁好,谁比谁高级之说,只要适用就好. 今天给大家分享一个不 ...

  6. 基于Python接口自动化测试框架+数据与代码分离(进阶篇)附源码

    引言 在上一篇<基于Python接口自动化测试框架(初级篇)附源码>讲过了接口自动化测试框架的搭建,最核心的模块功能就是测试数据库初始化,再来看看之前的框架结构: 可以看出testcase ...

  7. 基于Python接口自动化测试框架(初级篇)附源码

    引言 很多人都知道,目前市场上很多自动化测试工具,比如:Jmeter,Postman,TestLink等,还有一些自动化测试平台,那为啥还要开发接口自动化测试框架呢?相同之处就不说了,先说一下工具的局 ...

  8. 基于Python的HTTP接口自动化测试框架实现

    今天我们来讲一下基于Python的HTTP接口自动化测试框架的实现,范例如下: 一.测试需求描述 对服务后台一系列的http接口功能测试. 输入:根据接口描述构造不同的参数输入值 输出:XML文件 e ...

  9. 接口测试入门(4)--接口自动化测试框架 / list和map用法 / 随机选取新闻 (随机数生成) / 接口相关id映射

    一.接口自动化测试框架 为了更好的组织测试方法,测试用例并且持续集成,我们选择了  java+testNG(测试用例组织)+gitlab(代码版本管理)+Jenkins(持续集成工具) 作为一整套的自 ...

随机推荐

  1. php foundation knowledge!

    php foundation knowledge! 1 <?php 2 $p = "PII"; 3 define("XPI",3.1415926); 4 ...

  2. JavaScript string repeat methods All In One

    JavaScript string repeat methods All In One There are many ways in the ES-Next ways repeat ES2015 / ...

  3. nodemon all in one

    nodemon all in one https://nodemon.io/ https://github.com/remy/nodemon#nodemon https://www.npmjs.com ...

  4. Android Studio 4.x

    Android Studio 4.x https://developer.android.com/studio https://d.android.com/r/studio-ui/whats-new- ...

  5. taro router

    taro router https://nervjs.github.io/taro/docs/router.html bug import Taro, { Component, Config } fr ...

  6. Union international inc引进微信线下支付,开启消费无现金时代

    长期以来,Union international inc娱乐集团(公司编号:20151533091)因其客户来自全球各国,特别是除了美国之外的中国用户居多,因此公司一直和中国领先的社交软件微信保持着良 ...

  7. [转]RoboWare Studio的使用和发布器/订阅器的编写与测试

    原文地址:https://blog.csdn.net/han_l/article/details/77772352,转载主要方便随时查阅,如有版权要求,请及时联系. 开始ROS学习之前,先按照官网教程 ...

  8. Java对象内存布局

    本文转载自Java对象内存布局 导语 首先直接抛出问题 Unsafe.getInt(obj, fieldOffset)中的fieldOffset是什么, 类似还有compareAndSwapX(obj ...

  9. 在 TKE 中使用 Velero 迁移复制集群资源

    概述 Velero(以前称为Heptio Ark)是一个开源工具,可以安全地备份和还原,执行灾难恢复以及迁移 Kubernetes 群集资源和持久卷,可以在 TKE 集群或自建 Kubernetes ...

  10. Prometheus+Grafana+Alertmanager搭建全方位的监控告警系统

    prometheus安装和配置 prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据. 2.Client Library: 客户端库,检测应用程序代码,当 ...