新增接口字段批量校验功能
This commit is contained in:
parent
f1c95d54e2
commit
e6677c2d0a
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# @Author : caiweichao
|
||||
# @explain : 文件说明
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# @Author : caiweichao
|
||||
# @explain : 对于excel的结果进行批量校验
|
||||
from Commons.util.json_util import JsonUtil
|
||||
from Commons.util.logs import Log
|
||||
|
||||
|
||||
class ApiAssert:
|
||||
def __init__(self, checks: str, expecteds: str):
|
||||
"""
|
||||
:param checks: jsonpath
|
||||
:param expecteds:期望值
|
||||
"""
|
||||
self.checks: list = checks.split("\n")
|
||||
self.expecteds: list = expecteds.split("\n")
|
||||
|
||||
# 将全部对返回值进行校验
|
||||
def assert_all_expected(self, response):
|
||||
"""
|
||||
全部字段校验
|
||||
:param response:
|
||||
:return:
|
||||
"""
|
||||
if len(self.checks) != len(self.expecteds):
|
||||
return Exception("用例参数异常请检查!")
|
||||
try:
|
||||
for expected, check in dict(zip(self.expecteds, self.checks)).items():
|
||||
if (expected := JsonUtil.jsonToOneValue(response, rule=expected)) == check:
|
||||
Log.info(f"接口关键字段校验:{check} = {expected}")
|
||||
else:
|
||||
Log.error(f"接口关键字段校验未通过:{check} != {expected}")
|
||||
return False
|
||||
return True
|
||||
except Exception:
|
||||
Exception("校验异常请检查")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
|
@ -23,12 +23,18 @@
|
|||
2. operation_file --> 操作yaml excel
|
||||
3. ui_auto --> ui自动化的basicPage 解析allure测试报告
|
||||
4. util --> 工具类 json解析 数据库操作 日志记录 等
|
||||
5. api_auto --> 接口自动化工具类
|
||||
2. ConfigFile --> 项目的配置文件
|
||||
3. PageObject --> po文件
|
||||
4. TestCase --> 测试用例
|
||||
5. TestData --> 测试数据
|
||||
1. TestCase.xlsx --> 不同的sheet存放不同的api文件
|
||||
2. SchemaData --> 存放校验接口字段的yaml文件
|
||||
#### 更新日志
|
||||
- 20220619
|
||||
1. 接口自动化支持多关键字校验按照下图在excel中维护用例(写一个参数就换行)
|
||||
1. Commons/api_auto/batch_assert.py 这个类支持接口参数多字段校验一个失败即为失败
|
||||
2. [![Xj28pV.jpg](https://s1.ax1x.com/2022/06/19/Xj28pV.jpg)](https://imgtu.com/i/Xj28pV)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue