zoukankan      html  css  js  c++  java
  • python3读取excel实战

    '''
    参数化
    '''
    import xlrd,xlwt,json
    from api实现.读取参数化接口说明 import TestApi
    class ReadFileData:

    def __init__(self):
    self.tp = TestApi()
    def readFileData(self):
    filename='C:\Users\Administrator\Desktop\接口测试用例.xls'
    #读取文件
    workbook = xlrd.open_workbook(filename)
    #方法一;获取文件中所有的表
    # sheets = workbook.sheet_names() #['Sheet1', 'Sheet2', 'Sheet3']
    # worksheet = workbook.sheet_names()[0]
    # print(worksheet) #得到表名称
    #方法二:通过索引获取
    #sheets = workbook.sheet_by_index(0)#得到一个内存地址
    # 方法三:通过表名称获取
    sheets = workbook.sheet_by_name('接口用例')#得到一个内存地址
    '''
    sheets的名称,行数,列数
    sheets.name 表名称
    sheets.nrows 行数
    sheets.ncols 列数
    '''
    nums = sheets.nrows #得到行数
    #获取整行整列的值-->得到的是个列表
    #rows = sheets.row_values(0) #获取第一行的标题
    #cols = sheets.col_values(1) #获取第二列的数据
    # 获取单元格内容
    # print(sheets.cell(1, 0)) #1行0列
    # print(sheets.cell_value(2, 0))#2行0列
    # print(sheets.row(1)[0])#1行0列
    # # 获取单元格内容的数据类型
    # print(sheets.cell(1, 0).ctype)
    for i in range(1,nums):
    rows = sheets.row_values(i)
    #调用接口函数
    print('测试用例编号:',rows[0],'测试点:',rows[1])
    url=rows[3]+rows[4]
    #print(url)
    method=rows[2]
    data=eval(rows[5]) #eval可以将普通字符串转为字典
    asserts=rows[-2]
    headers=''
    self.tp.test_http(url,data,method,headers,asserts)
    rf = ReadFileData()
    print(rf.readFileData())
  • 相关阅读:
    卡特兰数
    hdu 1023 Train Problem II
    hdu 1022 Train Problem
    hdu 1021 Fibonacci Again 找规律
    java大数模板
    gcd
    object dection资源
    Rich feature hierarchies for accurate object detection and semantic segmentation(RCNN)
    softmax sigmoid
    凸优化
  • 原文地址:https://www.cnblogs.com/hally/p/9107860.html
Copyright © 2011-2022 走看看