Commit 75d32f08 by taoke

优化读取excle,若excle标题错误,则返回一串空列表

parent bc07b353
......@@ -27,65 +27,66 @@ def get_excelData(workBook,sheetName,caseName):
num_creator = list_title.index('creator')
num_autoCreator = list_title.index('autoCreator')
lis = []
idx = 0
try:
for one in workSheet.col_values(0):
result = ''.join(re.findall(r'[A-Za-z]', one)) # 抽取字母字符串
if caseName == result:
dict0 = {"url": "", "headers": "", "method": "", "reqData": "", "expectData": ""}
dict0['url'] = workSheet.cell_value(idx, num_url)
dict0['headers'] = workSheet.cell_value(idx, num_headers)
dict0['method'] = workSheet.cell_value(idx, num_method)
dict0['reqData'] = workSheet.cell_value(idx, num_reqData)
dict0['expectData'] = workSheet.cell_value(idx, num_expectData)
dict0['testPoint']= workSheet.cell_value(idx, num_testPoint)
dict0['caseNum']=workSheet.cell_value(idx, num_caseNum)
dict0['otherExpectData'] =workSheet.cell_value(idx, num_otherExpectData)
dict0['function'] =workSheet.cell_value(idx, num_function)
dict0['interface'] = workSheet.cell_value(idx, num_interface)
dict0['priority'] = workSheet.cell_value(idx, num_priority)
dict0['yapiAddress'] = workSheet.cell_value(idx, num_yapiAddress)
dict0['creator'] = workSheet.cell_value(idx, num_creator)
dict0['autoCreator'] = workSheet.cell_value(idx, num_autoCreator)
dict0['frontInterface'] = workSheet.cell_value(idx, num_frontInterface)
dict0['frontCondition'] = workSheet.cell_value(idx, num_frontCondition)
dict0['expectResult'] = workSheet.cell_value(idx, num_expectResult)
for one in workSheet.col_values(0):
result = ''.join(re.findall(r'[A-Za-z]', one)) # 抽取字母字符串
if caseName == result:
dict0 = {"url": "", "headers": "", "method": "", "reqData": "", "expectData": ""}
dict0['url'] = workSheet.cell_value(idx, num_url)
dict0['headers'] = workSheet.cell_value(idx, num_headers)
dict0['method'] = workSheet.cell_value(idx, num_method)
dict0['reqData'] = workSheet.cell_value(idx, num_reqData)
dict0['expectData'] = workSheet.cell_value(idx, num_expectData)
dict0['testPoint']= workSheet.cell_value(idx, num_testPoint)
dict0['caseNum']=workSheet.cell_value(idx, num_caseNum)
dict0['otherExpectData'] =workSheet.cell_value(idx, num_otherExpectData)
dict0['function'] =workSheet.cell_value(idx, num_function)
dict0['interface'] = workSheet.cell_value(idx, num_interface)
dict0['priority'] = workSheet.cell_value(idx, num_priority)
dict0['yapiAddress'] = workSheet.cell_value(idx, num_yapiAddress)
dict0['creator'] = workSheet.cell_value(idx, num_creator)
dict0['autoCreator'] = workSheet.cell_value(idx, num_autoCreator)
dict0['frontInterface'] = workSheet.cell_value(idx, num_frontInterface)
dict0['frontCondition'] = workSheet.cell_value(idx, num_frontCondition)
dict0['expectResult'] = workSheet.cell_value(idx, num_expectResult)
# json字符串转换成字典
try:
dict0['expectData'] = json.loads(dict0['expectData'])
except:
dict0['expectData'] = None
# json字符串转换成字典
try:
dict0['expectData'] = json.loads(dict0['expectData'])
except:
dict0['expectData'] = None
try:
dict0['otherExpectData'] = json.loads(dict0['otherExpectData'])
except:
dict0['otherExpectData'] = None
try:
dict0['otherExpectData'] = json.loads(dict0['otherExpectData'])
except:
dict0['otherExpectData'] = None
try:
dict0['reqData'] = json.loads(dict0['reqData'])
except:
dict0['reqData'] = None
try:
dict0['reqData'] = json.loads(dict0['reqData'])
except:
dict0['reqData'] = None
try:
dict0['headers'] = json.loads(dict0['headers'])
except:
dict0['headers'] = None
lis.append(dict0)
idx += 1
return lis
except:
print("excle中header值或参数或期望不是json字符串")
try:
dict0['headers'] = json.loads(dict0['headers'])
except:
dict0['headers'] = None
lis.append(dict0)
idx += 1
return lis
except:
list0=[{'url': '', 'headers': None, 'method': 'post', 'reqData': None, 'expectData': None, 'testPoint': '', 'caseNum': '', 'otherExpectData': None, 'function': '', 'interface': '', 'priority': '', 'yapiAddress': '', 'creator': '', 'autoCreator': '', 'frontInterface': '', 'frontCondition': '', 'expectResult': ''}]
print("检查excle中标题是否正确")
return list0
if __name__ == '__main__':
workBook = xlrd.open_workbook('../../test_case_data/bmc/bmc_testcase_20210513.xlsx')
li = get_excelData(workBook,"积分商城","focusSuccessIntegral")
print(li)
li = get_excelData(workBook,"账号信息基本功能","login")
for i in li :
print(i)
# {"Authorization": "","Content-Type":"application/x-www-form-urlencoded"}
\ No newline at end of file
......@@ -26,10 +26,10 @@ if __name__ == "__main__":
# 生成报告数据
pytest.main(['-v', '-s', test_case_dir, '--alluredir', './report/tmp'])
# 打开报告
os.system('allure serve ./report/tmp')
# os.system('allure serve ./report/tmp')
# 发送钉钉 ()
# dingTalk.dingTalk_markdown(secret="SEC465015385218e70a94f107a16f72dd33d8fc118c3b2a631e0433685302f2fbb3",
# webhook="https://oapi.dingtalk.com/robot/send?access_token=229908a83825ed56abbf728d3382e446a4e8a90e9ad302c37a036bcbccbbf9ee",
# message="")
dingTalk.dingTalk_markdown(secret="SEC465015385218e70a94f107a16f72dd33d8fc118c3b2a631e0433685302f2fbb3",
webhook="https://oapi.dingtalk.com/robot/send?access_token=229908a83825ed56abbf728d3382e446a4e8a90e9ad302c37a036bcbccbbf9ee",
message="")
......@@ -15,7 +15,7 @@ from config import BMCConfig
@allure.epic("账号信息基本功能")
# @allure.feature("账号信息基本功能")
class TestLogin():
workBook = xlrd.open_workbook(f'{BMCConfig.root_path}/test_case_data/bmc/bmc_base_info_2021513.xlsx')
workBook = xlrd.open_workbook(f'{BMCConfig.root_path}/test_case_data/bmc/bmc_testcase_20210513.xlsx')
@allure.story("账号信息基本功能")
@allure.severity("")
@allure.title("{inData[testPoint]}")
......
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