接口的单独封装的用例读取
读取excel case数据
import xlrd
import json
def getExcel(excelDir,sheetName,caseName):
lis = []
# 打开excel
workbook = xlrd.open_workbook(excelDir,formatting_info=True)
# sheets表
# worksheets = workbook.sheet_names()
# print(worksheets)
workSheet = workbook.sheet_by_name(sheetName)
# 读第一行
# print(workSheet.row_values(0))
# # 读第一列
# print(workSheet.col_values(0))
row = 1
for one in workSheet.col_values(0): # 遍历第0列
# print(one)
if caseName in one: # case名在遍历中字典中
reqbody = workSheet.cell_value(row,9)
expbody = workSheet.cell_value(row,11)
lis.append((json.loads(reqbody),json.loads(expbody))) # json转码成json格式
row += 1
return lis
# ---------------------------------------------------------------------
# 下面的扩展版版本--后期讲解
# def getExcel(excelDir,sheetName,caseName,*args):
# lis = []
# # 打开excel
# workbook = xlrd.open_workbook(excelDir,formatting_info=True)
# # sheets表
# # worksheets = workbook.sheet_names()
# # print(worksheets)
# workSheet = workbook.sheet_by_name(sheetName)
# # 读第一行
# print(workSheet.row_values(0))
# # # 读第一列
# # print(workSheet.col_values(0))
# colIdex = []
# for i in args:
# res = workSheet.row_values(0).index(i)
# # print(res)
# colIdex.append(res)
# # print(colIdex)
#
#
# row = 0
# for one in workSheet.col_values(0):
# if caseName in one:
# getColData = []
# for num in colIdex:
# res = workSheet.cell_value(row,num)
# getColData.append(res)
# lis.append(getColData)
# row += 1
# return lis
if __name__ == '__main__':
res = getExcel('路径文件','登录模块','Login')
# res = getExcel('路径文件','登录模块','Login','请求参数')
for one in res:
print(one)
嗨~今天你暴躁了吗?
~~~关注我,更多精彩内容带给你,关注私聊带走绝密知识~~~