You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import json
import re
from datetime import datetime
from PyQt5.QtCore import Qt, QTimer, QAbstractTableModel, QModelIndex, QPoint, QSize
from PyQt5.QtGui import QFont, QBrush, QColor
from openpyxl import load_workbook
class ExcelParser:
@staticmethod
def parseProcedure(filePath):
wb = load_workbook(filename=filePath)
if '测试脚本' in wb.sheetnames:
sheet = wb['测试脚本']
else:
sheet = wb.active
specInfo = {
"规程名称": sheet['B1'].value or "",
"规程编号": sheet['D1'].value or "",
"规程类型": sheet['F1'].value or ""
}
testCaseInfo = {
"测试用例": sheet['B2'].value or "",
"用例编号": sheet['D2'].value or "",
"工况描述": sheet['H2'].value or ""
}
testSteps = []
currentStep = None
stepCounter = 0
for rowIdx in range(5, sheet.max_row + 1):
cellA = sheet[f'A{rowIdx}'].value
cellB = sheet[f'B{rowIdx}'].value
cellC = sheet[f'C{rowIdx}'].value
if cellB is None and cellA is None:
continue
if cellA and re.match(r'STEP\d+[:]', str(cellA)):
if currentStep:
testSteps.append(currentStep)
stepCounter += 1
stepName = str(cellA).replace('', ':').strip()
stepDesc = str(cellB) if cellB else ""
currentStep = {
"步骤ID": stepName,
"步骤描述": stepDesc,
"操作类型": cellC if cellC else "",
"预期结果": sheet[f'D{rowIdx}'].value,
"子步骤": []
}
elif currentStep and cellA and str(cellA).isdigit():
subStep = {
"序号": int(cellA),
"操作": str(cellB) if cellB else "",
"操作类型": cellC if cellC else "",
"预期结果": sheet[f'D{rowIdx}'].value,
"实际结果": sheet[f'E{rowIdx}'].value,
"一致性": sheet[f'F{rowIdx}'].value if sheet[f'F{rowIdx}'].value == "" else "",
"测试时间": sheet[f'H{rowIdx}'].value,
"备注": sheet[f'I{rowIdx}'].value
}
currentStep["子步骤"].append(subStep)
if currentStep:
testSteps.append(currentStep)
return {
"文件路径": filePath,
"规程信息": {
"规程名称": specInfo["规程名称"],
"规程编号": specInfo["规程编号"],
"规程类型": specInfo["规程类型"]
},
"测试用例信息": {
"测试用例": testCaseInfo["测试用例"],
"用例编号": testCaseInfo["用例编号"],
"工况描述": testCaseInfo["工况描述"]
},
"测试步骤": testSteps
}