上接:接口自动化测试框架(一):框架介绍
读取用例数据
如上图,是我的测试用例自定义的标准数据的格式,我们将获取这些数据。代码如下:
#!/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)
实际结果如下:
阅读全文