littlebot
Published on 2025-04-17 / 1 Visits
0

【源码】基于Python的XMind测试用例转换工具

项目简介

本项目是基于Python的XMind测试用例转换工具,用于解决传统测试用例设计方式的痛点。它结合了XMind思维导图设计测试用例的便利性与常见测试用例管理系统的高效管理,通过制定通用测试用例模板,可从XMind文件中解析提取测试用例基本信息,合成常见测试用例管理系统所需的用例导入文件。

项目的主要特性和功能

  1. 多种格式转换:支持将XMind文件转换为TestLink的XML文件、Zentao的CSV文件,还提供TestSuites和TestCases两种级别的JSON数据接口。
  2. 高效设计用例:借助XMind的发散性和图形化思维,提高测试用例设计效率,便于用例评审。
  3. 多方式调用:提供命令行调用、Web界面使用和API调用等多种方式,以满足不同场景需求。
  4. 自动化发布:支持自动化更新打包上传至PYPI,同时根据版本号自动打Tag并推送到仓库。
  5. 执行结果统计:支持在TestCase和TestSuite中添加用例执行结果统计数据。

安装使用步骤

安装

使用pip3 install xmind2testcase进行安装;若需升级版本,使用pip3 install -U xmind2testcase

使用

命令行调用

``` Usage: xmind2testcase [path_to_xmind_file] [-csv] [-xml] [-json]

Example: xmind2testcase /path/to/testcase.xmind => output testcase.csv、testcase.xml、testcase.json xmind2testcase /path/to/testcase.xmind -csv => output testcase.csv xmind2testcase /path/to/testcase.xmind -xml => output testcase.xml xmind2testcase /path/to/testcase.xmind -json => output testcase.json ```

使用Web界面

``` Usage: xmind2testcase [webtool] [port_num]

Example: xmind2testcase webtool => launch the web testcase convertion tool locally -> 127.0.0.1:5001 xmind2testcase webtool 8000 => launch the web testcase convertion tool locally -> 127.0.0.1:8000 ```

API调用

参考以下示例代码: ```python import json import xmind from xmind2testcase.zentao import xmind_to_zentao_csv_file from xmind2testcase.testlink import xmind_to_testlink_xml_file from xmind2testcase.utils import xmind_testcase_to_json_file from xmind2testcase.utils import xmind_testsuite_to_json_file from xmind2testcase.utils import get_xmind_testcase_list from xmind2testcase.utils import get_xmind_testsuite_list

def main(): xmind_file = 'docs/xmind_testcase_template.xmind' print('Start to convert XMind file: %s' % xmind_file)

zentao_csv_file = xmind_to_zentao_csv_file(xmind_file)
print('Convert XMind file to zentao csv file successfully: %s' % zentao_csv_file)

testlink_xml_file = xmind_to_testlink_xml_file(xmind_file)
print('Convert XMind file to testlink xml file successfully: %s' % testlink_xml_file)

testsuite_json_file = xmind_testsuite_to_json_file(xmind_file)
print('Convert XMind file to testsuite json file successfully: %s' % testsuite_json_file)

testcase_json_file = xmind_testcase_to_json_file(xmind_file)
print('Convert XMind file to testcase json file successfully: %s' % testcase_json_file)

testsuites = get_xmind_testsuite_list(xmind_file)
print('Convert XMind to testsuits dict data:\n%s' % json.dumps(testsuites, indent=2, separators=(',', ': '), ensure_ascii=False))

testcases = get_xmind_testcase_list(xmind_file)
print('Convert Xmind to testcases dict data:\n%s' % json.dumps(testcases, indent=4, separators=(',', ': ')))

workbook = xmind.load(xmind_file)
print('Convert XMind to Json data:\n%s' % json.dumps(workbook.getData(), indent=2, separators=(',', ': '), ensure_ascii=False))

print('Finished conversion, Congratulations!')

if name == 'main': main() ```

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】