openpyxl获取表格测试数据(类与对象)
Posted sophia-985935365
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openpyxl获取表格测试数据(类与对象)相关的知识,希望对你有一定的参考价值。
from openpyxl import load_workbook
class Case:
def __init__(self):
self.case_id = None
self.title = None
self.method = None
self.url = None
self.data = None
self.expected = None
self.actually = None
self.result = None
class ReadData:
def __init__(self, file_name):
self.file_name = file_name
self.wb = load_workbook(self.file_name)
def read_data(self, sheet_name):
self.sheet_name = sheet_name
sheet =self.wb[self.sheet_name]
case_data = []
for row in range(2, int(sheet.max_row)+1):
case = Case()
case.case_id = sheet.cell(row, 1).value
case.title = sheet.cell(row, 2).value
case.method = sheet.cell(row, 3).value
case.url = sheet.cell(row, 4).value
case.data = sheet.cell(row, 5).value
case.expected = sheet.cell(row, 6).value
case_data.append(case)
return case_data
if __name__==‘__main__‘:
以上是关于openpyxl获取表格测试数据(类与对象)的主要内容,如果未能解决你的问题,请参考以下文章
Python + openpyxl 读取测试数据,通过Excel管理我们的测试用例数据