上接:接口自動化測試框架(一):框架介紹
讀取用例數(shù)據(jù)
如上圖,是我的測試用例自定義的標(biāo)準(zhǔn)數(shù)據(jù)的格式,我們將獲取這些數(shù)據(jù)。代碼如下:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from openpyxl import load_workbook
"""
@File:readCase.py
@Description: 描述
@Author:yeqinfang
@Email:yeqinfang@yeah.net
@Date: 2020/01/22
"""
class readCasedata(object):
def __init__(self, model, caseNum):
self.model = model
self.caseNum = caseNum
def getCase(self):
self.wb = load_workbook(filename='caseModel.xlsx', read_only=True)
self.ws = self.wb[self.model]
maxRow = self.ws.max_row
for i in range(2, maxRow+1):
if self.ws.cell(i, 1).value == self.caseNum:
return self.ws.cell(i, 1).row
else:
pass
def getPath(self):
row = self.getCase()
return self.ws.cell(row,3).value
def getHeaders(self):
row = self.getCase()
return self.ws.cell(row,4).value
def getData(self):
row = self.getCase()
return self.ws.cell(row,5).value
if __name__ == '__main__':
r1 = readCasedata("UM", "Test_01").getPath()
r2 = readCasedata("UM", "Test_01").getHeaders()
r3 = readCasedata("UM", "Test_01").getData()
print(r3)
實際結(jié)果如下:
閱讀全文