讀取Excel格式測試用例
測試用例編寫
測試用例編寫格式(個人習慣)
|
測試用例名稱 |
請求方法 |
接口路由 |
請求參數 |
請求體 |
斷言方法 |
斷言信息 |
|
title |
mothod |
router |
par |
body |
assert_mothod |
asserted |
|
測試用例一 |
GET |
/api/test |
{'id': '637c79c9d055780046de5593'} |
text |
"errorCode":0 |
|
|
測試用例一(登錄) |
POST |
/api/login/test |
{'account': 'admin', 'password': '123456'} |
text |
"errorCode":0 |
讀取Excel 測試用例
""" 封裝Excel測試用例讀取 """ import xlrd import os class Getdata: def __init__(self, file_path): """ :param file_path: 文件絕對路徑 """ if os.path.exists(file_path): self.file_path = file_path else: print('沒有找到%s文件路徑' % file_path) # 讀取 Excel 數據并將 int 類型轉換 def read_excel_data(self, sheet_name): """ :param sheet_name: Excel表名(Sheet) :return: 列表格式測試用例 """ workbook = xlrd.open_workbook(self.file_path) sheet = workbook.sheet_by_name(sheet_name) data = [] keys = [cell.value for cell in sheet.row(1)] # 第一行作為字典的鍵 for row in range(2, sheet.nrows): row_data = {} for col in range(sheet.ncols): value = sheet.cell(row, col).value if isinstance(value, float) and value.is_integer(): # 檢查值是否為整數 value = int(value) # 轉換為整數類型 row_data[keys[col]] = value data.append(row_data) return data

浙公網安備 33010602011771號