界面

convert.py

xmind转换为excel

# !/Desktop/codearea/pytestlearn2/venv/bin/python3.9
"""
@Author:Zhming
@Project:XmindtoExcelGUI
@File:convert
@Software:PyCharm
@Date:2022/3/3
"""import xlwt
from xmindparser import xmind_to_dictdef handle_xmind(filename):out = xmind_to_dict(filename)return out[0]['topic']['topics']def handle_path(topic, topics_lists, title):"""遍历解析后的xmind数据:param topic:xmind解析后的数据:param topics_lists:从topic提取的数据存放的列表:param title:从topic提取的title:return:"""# title去除首尾空格title = title.strip()# 如果调用本方法,则concatTitle赋值为第一个层级的名称(所属模块名称)if len(title) == 0:concatTitle = topic['title'].strip()else:concatTitle = title + '|' + topic['title'].strip()# 如果第一层下没有数据了,那么就把第一层级的名称填加到topics_lists里if topic.__contains__('topics') == False:topics_lists.append(concatTitle)# 如果有,那么就遍历下一个层级......这样就把所有title都写到topics_lists里了else:for d in topic['topics']:handle_path(d, topics_lists, concatTitle)def handle_title(topics):"""判断是title的类别:所属模块,所属子模块,用例,操作步骤,预期结果,备注:param topics: 传入topic的列表:return: 经过处理的字典,{'model': '...', 'sub_model': '...', 'case': '...', 'step': '...', 'expect': '...'}"""list = []for l in topics:dict = {}for i in l:if "模块" in i.split("_"):dict["model"] = i[3:]elif "子模块" in i.split("_"):dict["sub_model"] = i[4:]elif "测试用例:" in i or "测试用例:" in i:dict["case"] = i[5:]elif "步骤:" in i or "步骤:" in i:dict["step"] = i[3:]elif "预期:" in i or "预期:" in i:dict["expect"] = i[3:]elif "备注:" in i or "备注:" in i:dict["remark"] = i[3:]else:try:dict["case"] = dict["case"] + "_" + iexcept:passlist.append(dict)return listdef handle_topics(topics):index = 0title_lists = []# 遍历第一层级的分支(所属模块)for h in topics:topics_lists = []handle_path(h, topics_lists, '')# print("这个是lists,", topics_lists)# 取出topics下所有的title放到1个列表中for j in range(0, len(topics_lists)):title_lists.append(topics_lists[j].split('|'))return title_listsdef write_to_temp1(list, excelname):"""把解析的xmind文件写到xls文件里使用基础模板:param list: 经过处理的字典,格式 [{'model': '...', 'sub_model': '...', 'case': '...', 'step': '...','expect': '.'},{...},...]:param excelname: 输出的excel文件路径,文件名固定为:xmind文件名.xls:return:"""f = xlwt.Workbook()# 生成excel文件sheet = f.add_sheet('测试用例', cell_overwrite_ok=True)row0 = ['序号', '所属模块', '所属子模块', '测试用例', '执行步骤', '预期结果', '备注']# 生成第一行中固定表头内容for i in range(0, len(row0)):sheet.write(0, i, row0[i])# 把title写入xlsfor n in range(0, len(list)):# 第一列的序号sheet.write(n + 1, 0, n + 1)for index, d in enumerate(list):# 第二列及之后的用例数据try:sheet.write(index + 1, 1, d["model"])except:passtry:sheet.write(index + 1, 2, d["sub_model"])except:passtry:sheet.write(index + 1, 3, d["case"])except:passtry:sheet.write(index + 1, 4, d["step"])except:passtry:sheet.write(index + 1, 5, d["expect"])except:passtry:sheet.write(index + 1, 6, d["remark"])except:passf.save(excelname)def write_to_temp_jira(list, excelname):"""把解析的xmind文件写到xls文件里使用JIRA模板:param list: 经过处理的字典,格式 [{'model': '...', 'sub_model': '...', 'case': '...', 'step': '...','expect': '.'},{...},...]:param excelname: 输出的excel文件路径,文件名固定为:xmind文件名.xls:return:"""f = xlwt.Workbook()# 生成excel文件sheet = f.add_sheet('测试用例', cell_overwrite_ok=True)row0 = ['Team', 'TCID', 'Pre_Condition', '任务分类-TOC', 'Issue_type', 'Test-Set6','Summary', 'Component', 'Description','Fix_Version', 'Priority', 'Lables', 'Test_type', 'assignee', 'Step', 'Data', 'Expected_Result']# 生成第一行中固定表头内容for i in range(0, len(row0)):sheet.write(0, i, row0[i])# 把title写入xlsfor index, d in enumerate(list):# 第二列及之后的用例数据sheet.write(index + 1, 3, "用例设计")sheet.write(index + 1, 4, "Test")try:sheet.write(index + 1, 6, d["case"])except:passif d.get("model") and d.get("sub_model"):sheet.write(index + 1, 11, d["model"] + '_' + d["sub_model"])elif d.get("model") and d.get("sub_model") == None:sheet.write(index + 1, 11, d["model"])elif d.get("model") == None and d.get("sub_model"):sheet.write(index + 1, 11, d["sub_model"])else:passtry:sheet.write(index + 1, 12, "Manual")except:passtry:sheet.write(index + 1, 14, d["step"])except:passtry:sheet.write(index + 1, 16, d["expect"])except:passf.save(excelname)

untitled.py

Qt5Design生成的图形界面的代码

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.import os
from convert import handle_xmind,handle_title,handle_topics,write_to_temp1,write_to_temp_jira
from PyQt5 import QtCore, QtWidgetsclass Ui_MainWindow(object):fileName = ''filePath = ''template = ''def setupUi(self, MainWindow):MainWindow.setObjectName("MainWindow")MainWindow.resize(800, 450)MainWindow.setMinimumSize(QtCore.QSize(800, 450))MainWindow.setMaximumSize(QtCore.QSize(800, 450))self.centralwidget = QtWidgets.QWidget(MainWindow)self.centralwidget.setObjectName("centralwidget")self.pushButton = QtWidgets.QPushButton(self.centralwidget)self.pushButton.setGeometry(QtCore.QRect(410, 150, 341, 31))self.pushButton.setObjectName("pushButton")self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)self.lineEdit.setGeometry(QtCore.QRect(160, 41, 471, 31))self.lineEdit.setTabletTracking(False)self.lineEdit.setStatusTip("")self.lineEdit.setWhatsThis("")self.lineEdit.setInputMask("")self.lineEdit.setText("")self.lineEdit.setFrame(True)self.lineEdit.setEchoMode(QtWidgets.QLineEdit.Normal)self.lineEdit.setDragEnabled(False)self.lineEdit.setReadOnly(True)self.lineEdit.setObjectName("lineEdit")self.textEdit = QtWidgets.QTextEdit(self.centralwidget)self.textEdit.setGeometry(QtCore.QRect(40, 240, 711, 131))self.textEdit.setObjectName("textEdit")self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)self.pushButton_2.setGeometry(QtCore.QRect(660, 90, 91, 31))self.pushButton_2.setObjectName("pushButton_2")self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)self.lineEdit_2.setGeometry(QtCore.QRect(160, 90, 471, 31))self.lineEdit_2.setInputMask("")self.lineEdit_2.setReadOnly(True)self.lineEdit_2.setObjectName("lineEdit_2")self.label = QtWidgets.QLabel(self.centralwidget)self.label.setGeometry(QtCore.QRect(40, 40, 81, 31))self.label.setObjectName("label")self.label_2 = QtWidgets.QLabel(self.centralwidget)self.label_2.setGeometry(QtCore.QRect(40, 90, 81, 31))self.label_2.setObjectName("label_2")self.label_3 = QtWidgets.QLabel(self.centralwidget)self.label_3.setGeometry(QtCore.QRect(40, 210, 81, 31))self.label_3.setObjectName("label_3")self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)self.pushButton_3.setGeometry(QtCore.QRect(660, 40, 91, 31))self.pushButton_3.setObjectName("pushButton_3")self.label_4 = QtWidgets.QLabel(self.centralwidget)self.label_4.setGeometry(QtCore.QRect(40, 150, 101, 31))self.label_4.setObjectName("label_4")self.comboBox = QtWidgets.QComboBox(self.centralwidget)self.comboBox.setGeometry(QtCore.QRect(160, 150, 191, 31))self.comboBox.setEditable(False)self.comboBox.setDuplicatesEnabled(False)self.comboBox.setObjectName("comboBox")self.comboBox.addItem("基础模板")self.comboBox.addItem("JIRA模板")MainWindow.setCentralWidget(self.centralwidget)self.menubar = QtWidgets.QMenuBar(MainWindow)self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))self.menubar.setObjectName("menubar")MainWindow.setMenuBar(self.menubar)self.statusbar = QtWidgets.QStatusBar(MainWindow)self.statusbar.setObjectName("statusbar")MainWindow.setStatusBar(self.statusbar)self.retranslateUi(MainWindow)QtCore.QMetaObject.connectSlotsByName(MainWindow)# 信号,选择xmind文件self.pushButton_3.clicked.connect(self.open_file)# 信号,选择导出路径self.pushButton_2.clicked.connect(self.open_filepath)# 信号,把取到的值传给convert槽进行转换用例self.template = self.comboBox.currentText()self.comboBox.activated.connect(self.select_template)self.pushButton.clicked.connect(lambda: self.run(self.fileName, self.filePath, self.template))# 槽函数def open_file(self):fileName, fileType = QtWidgets.QFileDialog.getOpenFileName(self, "选取xmind文件", os.getcwd())self.fileName = fileNameself.lineEdit.setText(fileName)def open_filepath(self):filePath = QtWidgets.QFileDialog.getExistingDirectory(self, "选取输出文件夹", os.getcwd())self.filePath = filePathself.lineEdit_2.setText(filePath)def select_template(self):template = self.comboBox.currentText()self.template = templatedef run(self, xmind_file, out_filepath, temp):if xmind_file == "":QtWidgets.QMessageBox.warning(self, '警告', '源文件路径不能为空', QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes)elif xmind_file.endswith('.xmind') is False:QtWidgets.QMessageBox.warning(self, '警告', '请选择xmind格式的用例', QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes)else:xmind_name = os.path.basename(xmind_file)[:-6]# print("xmind文件路径:", xmind_file)if out_filepath == '':excel_file = os.path.join(os.path.dirname(xmind_file), xmind_name + '.xls')else:excel_file = os.path.join(out_filepath, xmind_name + '.xls')# print("excel输出路径:", excel_file)res = handle_topics(handle_xmind(xmind_file))if temp == "基础模板":write_to_temp1(handle_title(res), excel_file)elif temp == "JIRA模板":write_to_temp_jira(handle_title(res), excel_file)# print("转换完成!")self.textEdit.setText(f"xmind文件路径:{xmind_file}" + '\n' + f"excel输出路径:{excel_file}" + '\n' + "转换成功")def retranslateUi(self, MainWindow):_translate = QtCore.QCoreApplication.translateMainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))self.pushButton.setText(_translate("MainWindow", "开始转换"))self.pushButton_2.setText(_translate("MainWindow", "选择"))self.label.setText(_translate("MainWindow", "源文件路径:"))self.label_2.setText(_translate("MainWindow", "输出路径:"))self.label_3.setText(_translate("MainWindow", "运行结果:"))self.pushButton_3.setText(_translate("MainWindow", "选择"))self.label_4.setText(_translate("MainWindow", "选择输出模板:"))self.comboBox.setItemText(0, _translate("MainWindow", "基础模板"))self.comboBox.setItemText(1, _translate("MainWindow", "JIRA模板"))

run.py

主程序

# !/Desktop/codearea/pytestlearn2/venv/bin/python3.9
"""
@Author:Zhming
@Project:XmindtoExcelGUI
@File:run
@Software:PyCharm
@Date:2022/2/27
"""
import sys
from PyQt5 import QtWidgets
from untitled import Ui_MainWindowclass MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):def __init__(self, parent=None):super(MyWindow, self).__init__(parent)self.setupUi(self)self.setWindowTitle("Xmind用例转excel")if __name__ == '__main__':app = QtWidgets.QApplication(sys.argv)myWin = MyWindow()myWin.show()sys.exit(app.exec_())

完整项目可以去Gitee下载
https://gitee.com/zhaim/xmind2-excel.git

图形化界面的Xmind用例转excel工具相关推荐

  1. 不支持图形化界面的Linux系统如何显示图像化界面?飞腾服务器显示图像化界面方法,DISPLAY environment variable is undefined问题解决方法

    我用的本地 windows 环境访问的飞腾服务器,这个服务器里的系统是不支持图像化界面的,需要通过 display 指定自己的电脑来显示图像化界面. 命令如下,这个 ip 是对应自己电脑的,通过 ip ...

  2. 【小卒ubuntu使用第六篇】ubuntu下如何搭建远程控制服务(包括命令行方式的ssh局域网搭建、和图形化界面的teamviewer和anydesk工具的安装使用)

    最近由于实验室技术需要,组建网络服务,刚开始只是局限于局域网下,所以只采用ssh就足够了,连接同一个局域网,分布式控制机器合作,比较简单,但是后来主机天天携带不方便,就需要穿网的服务,经过自己的摸索和 ...

  3. (windows图形化界)粘滞键后门

    (windows图形化界)粘滞键后门 思路:windows图形化界面未登入用户时,连按5次Shift键粘滞键的程序依然可以弹出,若若把粘滞键的程序改为其他程序则有不一样的效果(如cmd程序). 一.手 ...

  4. 数据库软件MySQL的下载与安装+Navicat for MySQL图形化管理界面的下载与连接

    MySQL+Navicat 1 . mysql的下载与安装 2 . Navicat for MySQL图形化管理界面 1 . mysql的下载与安装 可以直接到官网下载 是免费的 官网下载地址选择的不 ...

  5. Mysql图形化管理界面的安装与使用

    Mysql有两张方式来执行请求,一是通过手打命令的方式,二是通过图形化界面来进行操作,后者本质上也是通过输入命令来执行请求,但是它可以使操作更简单,避免一些重复性的输入,下面来看看如何使用图像界面 1 ...

  6. 最小化安装 linux 安装图形化界面,那些最小化centos7安装图形化界面的坑

    环境:虚拟机下CentOS7: 一.安装图形化界面. 一条命令解决:yum -y groupinstall "GNOME Desktop" (双引号是必须的),早版本中可能是这个名 ...

  7. Docker容器中GUI软件的远程图形界面交互:mobaXterm+SSH,以脑影像处理软件FSL为例;FSL6.0.3完整安装与可视化;docker容器图形化;远程登录docker容器;

    前言   对docker容器中软件的操作,是基于命令行的,这就导致了习惯图形化界面的人比较难以使用docker,而它又是一个神器,所以很难受.一般情况下,可以给容器安装一个桌面环境,然后用类似VNC的 ...

  8. xclock 不出来界面_macOS 使用 XQuartz 支持 X11 实现 Linux 图形化界面显示

    更多奇技淫巧欢迎订阅博客:https://fuckcloudnative.io 前言 在 Windows 中相信大家已经很熟悉使用 Xmanager(Xshell), MobaXterm, Secur ...

  9. jtessboxeditorfx 界面显示不出来_macOS 使用 XQuartz 支持 X11 实现 Linux 图形化界面显示...

    更多奇技淫巧欢迎订阅博客:https://fuckcloudnative.io 前言 在 Windows 中相信大家已经很熟悉使用 Xmanager(Xshell), MobaXterm, Secur ...

最新文章

  1. 团队分数分配方法——BY 李栋
  2. C++是不是类型安全的?
  3. oracle 登录非系统用户,非Oracle用户使用操作系统验证登陆(/ as sysdba)
  4. vue中axios的封装以及使用
  5. 如果觉得午休时间太短怎么办?
  6. 使用MicroProfile应用隔板和背压
  7. java pkcs1转pkcs8_pkcs1与pkcs8格式RSA私钥互相转换
  8. [react] 和Component两者的区别是什么
  9. forEach与for循环的差别
  10. 我国高等数学教材不能误导学生
  11. 使用现有在线翻译服务进行代码翻译的体验
  12. 隔离太无聊!不如用Python实现愤怒的小鸟,看看能否通关!
  13. 关于微信公众号accesstoken
  14. 小学生获奖作品html,小学生优秀绘画作品图片展示
  15. h5 vr效果_H5案例|通过VR展示的那些烧脑游戏
  16. hive 各种 join (left outer join、join、full outer join)
  17. vue姓名筛选模糊搜索
  18. CDHtmlDialog屏蔽网页右键菜单
  19. Logistic Regression(1)
  20. carx2服务器维护不足什么问题,carx2赛车漂移

热门文章

  1. php在线留言,PHP在线提交留言直接发到邮箱
  2. 已解决Starting MySQL... ERROR The server quit without updating PID file
  3. 近十年我国竞争情报综述(转载)
  4. 利用手机号登录获取手机验证码
  5. Big-man酷谈overflow
  6. 卡尔曼滤波—Singer算法
  7. scala 中 foreach 的作用解释
  8. 成功的项目管理策略:减少成本,提高质量
  9. 微信聊天消息,好友转账消息的xml数据样本(分3种情况),以及各个字段含义
  10. HarmonyOS服务开放平台全面了解