首页 > 其他 > 详细

接口的单独封装的用例读取

时间:2021-03-29 09:05:15      阅读:28      评论:0      收藏:0      [点我收藏+]
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)

技术分享图片

接口的单独封装的用例读取

原文:https://www.cnblogs.com/blog-123/p/14590493.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!