Commit 9ac8d080 by ALuo

接口自动化框架V3

parent 5b897b7f
......@@ -14,7 +14,7 @@ def log_config():
"""配置日志"""
logger = logging.getLogger("ALuo")
logger.level = logging.NOTSET
log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "report/log/日志汇总.log")
log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "report/log/log_summary.log")
handler = logging.FileHandler(log_path, mode="a", encoding="utf-8")
format = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s - %(name)s')
handler.setFormatter(format)
......
......@@ -6,6 +6,8 @@
# Datetime: 2023/11/5 23:51
# Description: 对excel表进行操作
# ---------------------------------------------------------------------------
import os
import openpyxl
from interfaceAutoTest.common import alog
......@@ -16,18 +18,60 @@ from interfaceAutoTest.data_config.setting import *
class ReadExcel:
def __init__(self, table_name=None):
def __init__(self, author, table_name):
"""可根据需求填入工作表名,默认为配置文件中表名"""
# 获取ReadIni对象
self.read_ini = ReadIni()
# 获取配置文件的目录
self.config_dir = self.read_ini.config_dir
# 获取配置目录中除了ini文件外的所有路径
# 多用户操作
# 获取用户数据配置文件目录
self.author_dir = os.path.join(self.config_dir, author)
if not os.path.isdir(self.author_dir):
alog.error("请确保数据配置data_config目录下存在该用户的文件夹:" + author)
raise KeyError("请确保数据配置data_config目录下存在该用户的文件夹,详情请查看日志")
# 获取用户配置文件下的文件
filelist = os.listdir(self.author_dir)
excel_name = [file for file in filelist if file.endswith(".xlsx")]
if len(excel_name) != 1:
alog.error("请确保该用户的文件夹:" + author + " 存在或仅存在一个以'.xlsx'结尾的用例管理表:" + str(excel_name))
raise FileExistsError("请确保该用户文件下存在或仅存在一个用例管理的excel表")
self.excel_path = os.path.join(self.author_dir, excel_name[0])
case_data_path = os.path.join(self.author_dir, Case_Data + ".json")
expect_data_path = os.path.join(self.author_dir, Expect_Data + ".json")
sql_data_path = os.path.join(self.author_dir, Sql_Data + ".json")
# 读取excel表
self.wb = openpyxl.load_workbook(self.excel_path)
try:
self.ws = self.wb[table_name]
except:
alog.error("请确保该excel表中" + excel_name[0] + " 存在工作表:" + table_name)
raise KeyError("请确保表中存在该excel工作表,详情请查看日志")
# 获取json数据
self.case_data_dict = read_json.read_json(case_data_path)
self.expect_data_dict = read_json.read_json(expect_data_path)
if os.path.isfile(sql_data_path):
self.sql_data_dict = read_json.read_json(sql_data_path)
'''
# 单用户操作
self.excel_path = self.read_ini.get_file_path(Case_Excel)
case_data_path = self.read_ini.get_file_path(Case_Data)
expect_data_path = self.read_ini.get_file_path(Expect_Data)
sql_datta_path = self.read_ini.get_file_path(Sql_Data)
sql_data_path = self.read_ini.get_file_path(Sql_Data)
# 读取excel表
if table_name is None:
table_name = self.read_ini.get_table_name(Table_Name)
......@@ -38,11 +82,12 @@ class ReadExcel:
except:
alog.error("获取工作表错误,请检查:"+table_name)
raise KeyError("获取工作表错误,请检查,详情请查看日志")
'''
# 获取json数据
self.case_data_dict = read_json.read_json(case_data_path)
self.expect_data_dict = read_json.read_json(expect_data_path)
self.sql_data_dict = read_json.read_json(sql_datta_path)
# # 获取json数据
# self.case_data_dict = read_json.read_json(case_data_path)
# self.expect_data_dict = read_json.read_json(expect_data_path)
# self.sql_data_dict = read_json.read_json(sql_data_path)
def __get_cell_value(self, column: str, row: int):
"""根据传入的列号和行号获取某个单元格数据,并做预处理"""
......@@ -178,8 +223,8 @@ class ReadExcel:
if __name__ == '__main__':
read_excel = ReadExcel("BPM_add")
read_excel = ReadExcel("alin", "BPM-alin")
print(read_excel.get_case_data(3))
print(read_excel.get_expect_data(3))
print(read_excel.get_expect_data(13))
......@@ -22,9 +22,9 @@
"添加维度": {
"AddDemSuccess": {"code": "pkm", "name": "pokemon", "isDefault": 1, "description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsLong": {"code": "pkmpkmpkmpkmpkmpkmtespkmpkmpkmpkmpkmpkmtes","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsShort": {"code": "t","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsShort": {"code": "p","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsRepeat": {"code": "pkm","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsSpecial": {"code": "♥♠♤♂♀★☆※","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsSpecial": {"code": "p♥♠♤♂♀★☆※","name": "pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorCodeIsNone":{"code": "","name":"pokemon","isDefault": 0,"description": "测试57期的维度-测试专用"},
"AddDemErrorNameIsLong": {"code": "pkm1","name":"pokemonpokemonpokemonpokemonpokemon","isDefault": 0,"description": "测试57期的维度"},
"AddDemErrorNameIsShort": {"code": "pkm2","name":"po","isDefault": 0,"description": "测试57期的维度"},
......
{
"维度管理": {
"添加维度": {
"AddDemSuccess": {"state": true, "message": "添加维度成功!"},
"AddDemErrorCodeIsLong": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsShort": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsRepeat": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsSpecial": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsNone": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsLong": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsShort": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsNone": {"state": false, "message": "添加维度信息失败,维度名称【name】必填!"},
"AddDemErrorNameIsSpecial": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultIs-1": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultIs2": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultNotIsInt": {"state": false, "message": " Cannot deserialize value of type `java.lang.Integer` from String \"isDefault\": not a valid Integer value at [Source: (PushbackInputStream); line: 1, column: 50] (through reference chain: com.hotent.uc.params.demension.DemensionVo[\"isDefault\"])"},
"AddDemErrorDefaultIsSpecial": {"state": false, "message": " Cannot deserialize value of type `java.lang.Integer` from String \"\": not a valid Integer value at [Source: (PushbackInputStream); line: 1, column: 50] (through reference chain: com.hotent.uc.params.demension.DemensionVo[\"isDefault\"])"},
"AddDemErrorMsgIsLong": {"state": false, "message": "添加维度失败"}
}
}
}
{
"认证接口":{
"登录系统":{
"LoginSuccess": {"password": "MTIzNDU2","username": "admin"},
"LoginPasswordDataError":{"password": "MTIzNDU212q","username": "admin"},
"LoginPasswordDataIsLong":{"password": "MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2MTIzNDU2","username": "admin"},
"LoginPasswordDataIsShort":{"password": "M","username": "admin"},
"LoginPasswordDataIsNone":{"password": "","username": "admin"},
"LoginPasswordDataIsSpecial":{"password": "@@!@@!","username": "admin"},
"LoginUsernameDataError":{"password": "MTIzNDU2","username": "admin1"},
"LoginUsernameDataIsLong":{"password": "MTIzNDU2","username": "adminadminadminadmin"},
"LoginUsernameDataIsShort":{"password": "MTIzNDU2","username": "a"},
"LoginUsernameDataIsNone":{"password": "MTIzNDU2","username": ""},
"LoginUsernameDataIsSpecial": {"password": "MTIzNDU2","username": "@@!@@!"},
"LoginUsernameError": {"password": "MTIzNDU2","user": "admin"},
"LoginUsernameIsNone": {"password": "MTIzNDU2","": "admin"},
"LoginPasswordError": {"pass": "MTIzNDU2","username": "admin"},
"LoginPasswordIsNone": {"": "MTIzNDU2","username": "admin"}
}
}
}
......@@ -17,25 +17,6 @@
"LoginPasswordError": {"state": false, "message":"账号或密码错误"},
"LoginPasswordIsNone": {"state": false, "message":"账号或密码错误"}
}
},
"维度管理": {
"添加维度": {
"AddDemSuccess": {"state": true, "message": "添加维度成功!"},
"AddDemErrorCodeIsLong": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsShort": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsRepeat": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsSpecial": {"state": false, "message": "添加维度失败"},
"AddDemErrorCodeIsNone": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsLong": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsShort": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsNone": {"state": false, "message": "添加维度失败"},
"AddDemErrorNameIsSpecial": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultIs-1": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultIs2": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultNotIsInt": {"state": false, "message": "添加维度失败"},
"AddDemErrorDefaultIsSpecial": {"state": false, "message": "添加维度失败"},
"AddDemErrorMsgIsLong": {"state": false, "message": "添加维度失败"}
}
}
}
......
2023-11-06 20:26:27,849 - read_excel.py[line:106] - ERROR: 用例数据获取失败 - ALuo
2023-11-06 20:26:27,849 - read_excel.py[line:106] - ERROR: 用例数据获取失败 - ALuo
2023-11-06 20:26:27,850 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-06 20:28:27,085 - read_excel.py[line:106] - ERROR: 用例数据获取失败 - ALuo
2023-11-06 20:28:27,085 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-06 20:29:54,275 - read_excel.py[line:106] - ERROR: 用例数据获取失败 - ALuo
2023-11-06 20:29:54,275 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-06 20:30:16,160 - read_excel.py[line:118] - ERROR: 期望数据获取失败 - ALuo
2023-11-06 20:30:16,160 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-07 09:01:13,243 - read_excel.py[line:106] - ERROR: 用例数据获取失败 - ALuo
2023-11-07 09:01:13,244 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-07 09:01:51,434 - db.py[line:63] - ERROR: 数据库执行删除操作失败,请检查 - ALuo
2023-11-07 09:07:52,289 - test_bpm.py[line:27] - ERROR: {'code': 'pkm', 'name': 'pokemon', 'isDefault': 1, 'description': '测试57期的维度-测试专用'} - ALuo
2023-11-07 09:07:52,289 - db.py[line:62] - ERROR: 数据库语句执行错误 - ALuo
2023-11-07 09:09:40,180 - read_excel.py[line:130] - ERROR: sql数据获取失败 - ALuo
2023-11-07 09:09:40,180 - read_excel.py[line:171] - ERROR: 获取excel表中数据失败,请查看是否存在空行,当前最大行:15 - ALuo
2023-11-07 09:35:37,252 - test_bpm.py[line:47] - ERROR: 反向-code过长 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkmpkmpkmpkmpkmpkmtespkmpkmpkmpkmpkmpkmtes】在系统中已存在!","value":""} 用例数据:{'code': 'pkmpkmpkmpkmpkmpkmtespkmpkmpkmpkmpkmpkmtes', 'name': 'pokemon', 'isDefault': 0, 'description': '测试57期的维度-测试专用'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:37,670 - test_bpm.py[line:47] - ERROR: 反向-code过短 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【t】在系统中已存在!","value":""} 用例数据:{'code': 't', 'name': 'pokemon', 'isDefault': 0, 'description': '测试57期的维度-测试专用'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:37,789 - test_bpm.py[line:47] - ERROR: 反向-code重复 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm】在系统中已存在!","value":""} 用例数据:{'code': 'pkm', 'name': 'pokemon', 'isDefault': 0, 'description': '测试57期的维度-测试专用'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:37,903 - test_bpm.py[line:47] - ERROR: 反向-code为特殊字符 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【♥♠♤♂♀★☆※】在系统中已存在!","value":""} 用例数据:{'code': '♥♠♤♂♀★☆※', 'name': 'pokemon', 'isDefault': 0, 'description': '测试57期的维度-测试专用'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,041 - test_bpm.py[line:47] - ERROR: 反向-name过长 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm1】在系统中已存在!","value":""} 用例数据:{'code': 'pkm1', 'name': 'pokemonpokemonpokemonpokemonpokemon', 'isDefault': 0, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,226 - test_bpm.py[line:47] - ERROR: 反向-name过短 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm2】在系统中已存在!","value":""} 用例数据:{'code': 'pkm2', 'name': 'po', 'isDefault': 0, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,344 - test_bpm.py[line:47] - ERROR: 反向-name为空 断言失败,因为 {"state":false,"message":"添加维度信息失败,维度名称【name】必填!","logId":"1721702919436255232"} 用例数据:{'code': 'pkm3', 'name': '', 'isDefault': 0, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,513 - test_bpm.py[line:47] - ERROR: 反向-name为特殊字符 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm4】在系统中已存在!","value":""} 用例数据:{'code': 'pkm4', 'name': '♥♠♤♂♀★☆※', 'isDefault': 0, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,635 - test_bpm.py[line:47] - ERROR: 反向-isDefault为-1 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm5】在系统中已存在!","value":""} 用例数据:{'code': 'pkm5', 'name': 'pokemon', 'isDefault': -1, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,750 - test_bpm.py[line:47] - ERROR: 反向-isDefault为2 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm6】在系统中已存在!","value":""} 用例数据:{'code': 'pkm6', 'name': 'pokemon', 'isDefault': 2, 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:38,867 - test_bpm.py[line:47] - ERROR: 反向-isDefault不为整形 断言失败,因为 {"state":false,"message":" Cannot deserialize value of type `java.lang.Integer` from String \"isDefault\": not a valid Integer value\n at [Source: (PushbackInputStream); line: 1, column: 50] (through reference chain: com.hotent.uc.params.demension.DemensionVo[\"isDefault\"])","logId":"1721702921613099008"} 用例数据:{'code': 'pkm7', 'name': 'pokemon', 'isDefault': 'isDefault', 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:39,032 - test_bpm.py[line:47] - ERROR: 反向-isDefault为特殊字符 断言失败,因为 {"state":false,"message":" Cannot deserialize value of type `java.lang.Integer` from String \"※\": not a valid Integer value\n at [Source: (PushbackInputStream); line: 1, column: 50] (through reference chain: com.hotent.uc.params.demension.DemensionVo[\"isDefault\"])","logId":"1721702922271604736"} 用例数据:{'code': 'pkm8', 'name': 'pokemon', 'isDefault': '※', 'description': '测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
2023-11-07 09:35:39,250 - test_bpm.py[line:47] - ERROR: 反向-msg过长 断言失败,因为 {"state":false,"message":"添加维度失败,维度编码【pkm9】在系统中已存在!","value":""} 用例数据:{'code': 'pkm9', 'name': 'pokemon', 'isDefault': 0, 'description': '测试57期的维度测试57期的维度测试57期的维度测试57期的维度测试57期的维度测试57期的维度测试57期的维度测试57期的维度测试57期的维度'} 期望数据:{'state': False, 'message': '添加维度失败'} - ALuo
......@@ -17,4 +17,4 @@ log_file_level=error
;设置日志在文件中的信息格式
log_file_format=%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s
;设置文件日志中时间显示的格式
log_file_date_format=%年-%月-%日 %H:%M:%S
log_file_date_format=%Y-%m-%d %H:%M:%S
\ No newline at end of file
......@@ -23,8 +23,8 @@ def req_fix():
req = RequestMethod()
return req
# def pytest_collection_modifyitems(items):
# # item表示每个测试用例,解决用例名称中文显示问题
# for item in items:
# item.name = item.name.encode("utf-8").decode("unicode-escape")
# item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")
\ No newline at end of file
def pytest_collection_modifyitems(items):
# item表示每个测试用例,解决用例名称中文显示问题
for item in items:
item.name = item.name.encode("utf-8").decode("unicode-escape")
item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")
\ No newline at end of file
......@@ -16,11 +16,12 @@ from interfaceAutoTest.common.read_excel import ReadExcel
class TestBPM:
read_excel = ReadExcel()
read_excel = ReadExcel("alin", "BPM-alin")
@allure.epic("BPM-ALin")
@pytest.mark.parametrize("case_module, case_api, case_title, case_level, case_url, "
"case_method, case_mime, case_data, expect_data, sql_type, sql_data, update_key, row", ReadExcel("BPM_add").get_datas())
"case_method, case_mime, case_data, expect_data, sql_type, sql_data, update_key, row",
read_excel.get_datas())
def test_bpm(self, db_fix, req_fix, case_module, case_api, case_title, case_level, case_url, case_method,
case_mime, case_data, expect_data, sql_type, sql_data, update_key, row):
# 判断sql语句是否为deleteReadExcel("BPM_add")
......@@ -45,12 +46,12 @@ class TestBPM:
for key in expect_data:
assert expect_data[key] == res.json()[key]
except:
ReadExcel("BPM_add").write_excel(result="断言失败", row=row)
TestBPM.read_excel.write_excel(result="断言失败", row=row)
alog.error(case_title + " 断言失败,因为 " + res.text + " 用例数据:" + str(case_data) + " 期望数据:" + str(expect_data))
raise AssertionError("断言失败")
else:
print("断言成功")
ReadExcel("BPM_add").write_excel(result="断言成功", row=row)
TestBPM.read_excel.write_excel(result="断言成功", row=row)
if __name__ == '__main__':
pytest.main()
......
......@@ -23,9 +23,8 @@ def req_fix():
req = RequestMethod()
return req
#
# def pytest_collection_modifyitems(items):
# # item表示每个测试用例,解决用例名称中文显示问题
# for item in items:
# item.name = item.name.encode("utf-8").decode("unicode-escape")
# item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")
def pytest_collection_modifyitems(items):
# item表示每个测试用例,解决用例名称中文显示问题
for item in items:
item.name = item.name.encode("utf-8").decode("unicode-escape")
item._nodeid = item._nodeid.encode("utf-8").decode("unicode-escape")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment