问题:做测试的朋友们经常会用到xmind这个工具来梳理测试点或写测试用例,但是xmind8没有自带的统计测试用例,其他版本的xmind有些自带节点数量统计功能,但也也不会累计最终的数量,导致统计测试工作量比较困难。

解决方法:利用python开发小工具,实现同一份xmind文件中一个或多个sheet页的用例数量统计功能。

一、源码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'zhongxintao'
import tkinter as tk
from tkinter import filedialog, messagebox
from xmindparser import xmind_to_dict
import xmind class ParseXmind:
def __init__(self, root):
self.count = 0
self.case_fail = 0
self.case_success = 0
self.case_block = 0
self.case_priority = 0 # total汇总用
self.total_cases = 0
self.total_success = 0
self.total_fail = 0
self.total_block = 0
self.toal_case_priority = 0 # 设置弹框标题、初始位置、默认大小
root.title(u'xmind文件解析及用例统计工具')
width = 760
height = 600
xscreen = root.winfo_screenwidth()
yscreen = root.winfo_screenheight()
xmiddle = (xscreen - width) / 2
ymiddle = (yscreen - height) / 2
root.geometry('%dx%d+%d+%d' % (width, height, xmiddle, ymiddle)) # 设置2个Frame
self.frm1 = tk.Frame(root)
self.frm2 = tk.Frame(root) # 设置弹框布局
self.frm1.grid(row=1, padx='20', pady='20')
self.frm2.grid(row=2, padx='30', pady='30') self.but_upload = tk.Button(self.frm1, text=u'上传xmind文件', command=self.upload_files, bg='#dfdfdf')
self.but_upload.grid(row=0, column=0, pady='10')
self.text = tk.Text(self.frm1, width=55, height=10, bg='#f0f0f0')
self.text.grid(row=1, column=0)
self.but2 = tk.Button(self.frm2, text=u"开始统计", command=self.new_lines, bg='#dfdfdf')
self.but2.grid(row=0, columnspan=6, pady='10')
self.label_file = tk.Label(self.frm2, text=u"文件名", relief='groove', borderwidth='2', width=25,
bg='#FFD0A2')
self.label_file.grid(row=1, column=0)
self.label_case = tk.Label(self.frm2, text=u"用例数", relief='groove', borderwidth='2', width=10,
bg='#FFD0A2').grid(row=1, column=1)
self.label_pass = tk.Label(self.frm2, text=u"成功", relief='groove', borderwidth='2', width=10,
bg='#FFD0A2').grid(row=1, column=2)
self.label_fail = tk.Label(self.frm2, text=u"失败", relief='groove', borderwidth='2', width=10,
bg='#FFD0A2').grid(row=1, column=3)
self.label_block = tk.Label(self.frm2, text=u"阻塞", relief='groove', borderwidth='2', width=10,
bg='#FFD0A2').grid(row=1, column=4)
self.label_case_priority = tk.Label(self.frm2, text="p0case", relief='groove', borderwidth='2',
width=10, bg='#FFD0A2').grid(row=1, column=5) def count_case(self, li):
"""统计xmind中的用例数"""
for i in range(len(li)):
if li[i].__contains__('topics'):
# 带topics标签表示有子标题,递归执行方法
self.count_case(li[i]['topics'])
# 不带topics表示无子标题,此级别即是用例
else:
# 有标记成功或失败时会有makers标签
if li[i].__contains__('makers'):
for mark in li[i]['makers']:
# 成功
if mark == "symbol-right":
self.case_success += 1
# 失败
elif mark == "symbol-wrong":
self.case_fail += 1
# 阻塞
elif mark == "symbol-attention":
self.case_block += 1
# 优先级
elif mark == "priority-1":
self.case_priority += 1
# 用例总数
self.count += 1 def new_line(self, filename, row_number):
"""用例统计表新增一行"""
# sheets是一个list,可包含多sheet页
sheets = xmind_to_dict(filename) # 调用此方法,将xmind转成字典
for sheet in sheets:
print(sheet)
# 字典的值sheet['topic']['topics']是一个list
my_list = sheet['topic']['topics']
print(my_list)
self.count_case(my_list) # 插入一行统计数据
lastname = filename.split('/')
self.label_file = tk.Label(self.frm2, text=lastname[-1], relief='groove', borderwidth='2', width=25)
self.label_file.grid(row=row_number, column=0) self.label_case = tk.Label(self.frm2, text=self.count, relief='groove', borderwidth='2', width=10)
self.label_case.grid(row=row_number, column=1)
self.label_pass = tk.Label(self.frm2, text=self.case_success, relief='groove', borderwidth='2',
width=10)
self.label_pass.grid(row=row_number, column=2)
self.label_fail = tk.Label(self.frm2, text=self.case_fail, relief='groove', borderwidth='2', width=10)
self.label_fail.grid(row=row_number, column=3)
self.label_block = tk.Label(self.frm2, text=self.case_block, relief='groove', borderwidth='2', width=10)
self.label_block.grid(row=row_number, column=4)
self.label_case_priority = tk.Label(self.frm2, text=self.case_priority, relief='groove', borderwidth='2',
width=10)
self.label_case_priority.grid(row=row_number, column=5)
self.total_cases += self.count
self.total_success += self.case_success
self.total_fail += self.case_fail
self.total_block += self.case_block
self.toal_case_priority += self.case_priority def new_lines(self):
"""用例统计表新增多行"""
# 从text中获取所有行
lines = self.text.get(1.0, tk.END)
row_number = 2
# 分隔成每行
for line in lines.splitlines():
if line == '':
break
print(line)
self.new_line(line, row_number)
row_number += 1 # total汇总行
self.label_file = tk.Label(self.frm2, text='total', relief='groove', borderwidth='2', width=25)
self.label_file.grid(row=row_number, column=0)
self.label_case = tk.Label(self.frm2, text=self.total_cases, relief='groove', borderwidth='2', width=10)
self.label_case.grid(row=row_number, column=1) self.label_pass = tk.Label(self.frm2, text=self.total_success, relief='groove', borderwidth='2',
width=10)
self.label_pass.grid(row=row_number, column=2)
self.label_fail = tk.Label(self.frm2, text=self.total_fail, relief='groove', borderwidth='2', width=10)
self.label_fail.grid(row=row_number, column=3)
self.label_block = tk.Label(self.frm2, text=self.total_block, relief='groove', borderwidth='2',
width=10)
self.label_block.grid(row=row_number, column=4) self.label_case_priority = tk.Label(self.frm2, text=self.toal_case_priority, relief='groove',
borderwidth='2',
width=10)
self.label_case_priority.grid(row=row_number, column=5) def upload_files(self):
"""上传多个文件,并插入text中"""
select_files = tk.filedialog.askopenfilenames(title=u"可选择1个或多个文件")
for file in select_files:
self.text.insert(tk.END, file + '\n')
self.text.update() if __name__ == '__main__':
r = tk.Tk()
ParseXmind(r)
r.mainloop()

二、工具使用说明

1、xmind文件中使用下列图标进行分类标识:

标记表示p0级别case:数字1

标记表示执行通过case:绿色√

标记表示执行失败case:红色×

标记表示执行阻塞case:橙色!

2、执行代码

3、在弹框内【上传xmind文件】按钮

4、在弹框内【开始统计】按钮
 

三、实现效果

python提效小工具-统计xmind用例数量的更多相关文章

  1. java性能问题排查提效脚本工具

    在性能测试过程中,往往会出现各种各样的性能瓶颈.其中java常见瓶颈故障模型有cpu资源瓶颈:文件IO瓶颈:网络IO瓶颈:内存资源瓶颈:资源消耗不高程序本身执行慢等场景模型. 如何快速定位分析这些类型 ...

  2. 前端必备,5大mock省时提效小tips,用了提前下班一小时

    ​ 一.一些为难前端的业务场景 在我的工作经历里,需要等待后端童鞋配合我的情形大概有以下几种: a.我们跟外部有项目合作,需要调用到第三方接口. 一般这种情况下,商务那边谈合同,走流程,等第三方审核, ...

  3. Python趣味实用小工具

    代码地址如下:http://www.demodashi.com/demo/12918.html python 趣味实用小工具 概述 用python实现的三个趣味实用小工具: 图片转Execl工具 , ...

  4. Python+Tkinter 密保小工具

    上图 代码 核心 编解码方面 Tkinter界面更新 总结 昨天被一同学告知,网上的一个QQ密码库中有我的一条记录,当时我就震惊了,赶紧换了密码.当然了,这件事也给了我一个警示,那就是定期的更换自己的 ...

  5. 几个可以提高工作效率的Python内置小工具

    在这篇文章里,我们将会介绍4个Python解释器自身提供的小工具.这些小工具在笔者的日常工作中经常用到,减少了各种时间的浪费,然而,却很容易被大家忽略.每当有新来的同事看到我这么使用时,都忍不住感叹, ...

  6. python tkinter模块小工具界面

    代码 #-*-coding:utf-8-*- import os from tkinter import * root=Tk() root.title('小工具') #清空文本框内容 def clea ...

  7. 纯Python综合图像处理小工具(1)分通道直方图

    平时工作经常需要做些图像分析,需要给图像分通道,计算各个通道的直方图分布特点,这个事儿photoshop也能做,但是用起来不方便,且需要电脑上安装有PS软件,如果用OpenCV, 更是需要在visua ...

  8. 纯Python综合图像处理小工具(4)自定义像素级处理(剪纸滤镜)

      上一节介绍了python PIL库自带的10种滤镜处理,现成的库函数虽然用起来方便,但是对于图像处理的各种实际需求,还需要开发者开发自定义的滤镜算法.本文将给大家介绍如何使用PIL对图像进行自定义 ...

  9. 纯Python综合图像处理小工具(3)10种滤镜算法

    <背景>  滤镜处理是图像处理中一种非常常见的方法.比如photoshop中的滤镜效果,除了自带的滤镜,还扩展了很多第三方的滤镜效果插件,可以对图像做丰富多样的变换:很多手机app实现了实 ...

随机推荐

  1. Python Flask Blueprint 蓝图

    Python Flask Blueprint 蓝图 本篇来了解一下 Flask 中 Blueprint 蓝图,什么蓝图 ..就是一个分模块的扩展而已,用来让不同的 业务模块api 分到不同的pytho ...

  2. Linux—搭建Apache(httpd)服务

    1.httpd简介? http是Apache超文本传输协议服务器的主程序.它是一个独立的后台进程,能够处理请求的子进程和线程. http常用用的两个版本是httpd-2.2和httpd-2.4 Cen ...

  3. powershell和cmd对比

    前言 计算机啊这东西,本质上是硬件和软件的综合体.如果只有硬件没有软件的话,这也是台辣鸡而已.而计算机软件中最靠近硬件的一层,就是操作系统层. 操作系统有很多种,比如Unix/Linux/Mac OS ...

  4. DolphinScheduler 荣获 2021 中国开源云联盟优秀开源项目奖!

    点击上方 蓝字关注我们 好消息,中国开源云联盟(China Open Source Cloud League,简称"COSCL")于近日公布 2021 杰出开源贡献者.优秀开源项目 ...

  5. async...await在tcp通讯中的正确用法

    引言 编程能力在不断的总结中进步以及成长,最近的半年里,对之前的开源项目代码进行回归,在重构的过程中进行了很多思考,很多次都想放弃重构,毕竟一个已经在使用的项目,重构基础代码就相当于重新开发了,不过最 ...

  6. django中的静态文件

    静态文件 1.什么是静态文件 在django中静态文件是指那些图片.css样式.js样式.视频.音频等静态资源. 2.为什么要配置静态文件 这些静态文件往往不需要频繁的进行变动,如果我们将这些静态文件 ...

  7. Docker 13 Dockerfile

    参考源 https://www.bilibili.com/video/BV1og4y1q7M4?spm_id_from=333.999.0.0 https://www.bilibili.com/vid ...

  8. Reader和Writer区别final.finally.finalize区别

    Reader和Writer是字符操作流,Writer是输出的,而Reader是输入的. 首先找到一个文件,比如:File file=new File("."+File.separa ...

  9. RS485自动收发切换电路 [原创www.cnblogs.com/helesheng]

    RS485是最常见的一种远距离可靠传输和组网的UART串口信号接口协议.与同样传输UART串口信号的RS422协议相比,RS485使用半双工通信,即只有一个信道,在同一时刻要么从A到B,要么从B到A传 ...

  10. Linux操作系统学习(运维必会)

    Linux一切皆文件,最高权限的账户root. 1.开机登录 开机会启动很多进程,在Windows上叫"服务"(service),在Linux上叫做"守护进程" ...