正文

Xmind用例导入到TAPD的解决方案(xmind应用技巧)万万没想到

文章摘要

本文介绍了如何将XMind文件转换为Zentao的CSV格式,并详细说明了相关的转换函数及其功能。核心内容包括: 1. **函数功能**:`xmind_to_zentao_csv_file`负责将XMind文件转换为Zentao的CSV格式,并处理测试用例的前置条件、步骤、预期结果等信息。 2. **数据格式**:引入了新的数据格式(TapD),其字段包括所属模块、用例标题、需求ID、前置条件、用例步骤、预期结果、用例类型、用例状态、用例等级等。 3. **新功能**:新增了获取需求ID的功能,修改了用例类型判断逻辑,以及增加了对测试结果和备注说明的处理。 4. **代码实现**:提供了`gen_a_testcase_row_tapd`函数,用于生成符合TapD格式的测试用例行,并修改了`get_execution_type`函数以更精确地判断用例类型。 总结而言,文章通过代码实现XMind到Zentao CSV的转换,提升了测试数据的组织和管理效率。

#修改表头 def xmind_to_zentao_csv_file(xmind_file): “””Convert XMind file to a zentao csv file””” xmind_file=get_absolute_path(xmind_file) #路径处理 logging.info(‘Start converting XMind file(%s) to zentao file…’, xmind_file) testcases=get_xmind_testcase_list(xmind_file) #解析xmind文档,得到原始数据 # print(“testcases”,testcases) #fileheader=[“所属模块”,”用例标题”,”前置条件”,”步骤”, “预期”, “关键词>用例状态”, “优先级”, “用例类型”, “适用阶段?”] fileheader_tapd=[“用例目录”,”用例名称”,”需求ID”,”前置条件”,”用例步骤”,”预期结果”,”用例类型”,”用例状态”,”用例等级”,”创建人”,”测试结果”,”备注说明”] zentao_testcase_rows=[fileheader_tapd] for testcase in testcases: #row=gen_a_testcase_row(testcase) row=gen_a_testcase_row_tapd(testcase) zentao_testcase_rows.append(row) zentao_file=xmind_file[:-6] + ‘.csv’ if os.path.exists(zentao_file): #判断括号里的文件是否存在 os.remove(zentao_file) # logging.info(‘The zentao csv file already exists, return it directly: %s’, zentao_file) # return zentao_file with open(zentao_file, ‘w’, encoding=’utf8′) as f: writer=csv.writer(f) writer.writerows(zentao_testcase_rows) logging.info(‘Convert XMind file(%s) to a zentao csv file(%s) successfully!’, xmind_file, zentao_file) return zentao_file #修改为tapd的数据格式、增加获取需求ID def gen_a_testcase_row_tapd(testcase_dict): #用例标题 case_title=testcase_dict[‘name’] #需求ID 产品名称里的目录获取 requirement_id, product_catalog=gen_requirement_id(testcase_dict[‘product’]) # 所属模块 case_module=product_catalog +”-” + gen_case_module(testcase_dict[‘suite’]) #前置条件 case_precontion=testcase_dict[‘preconditions’] #步骤 预期结果 case_step, case_expected_result=gen_case_step_and_expected_result(testcase_dict[‘steps’]) #用例类型 case_type=gen_case_type(testcase_dict[‘execution_type’]) # case_type=”功能测试” #用例状态 case_status=”正常” #用例等级 case_priority=gen_case_priority(testcase_dict[‘importance’]) #创建人 case_created_by=”” #测试结果 case_actual_result=”” row=[case_module,case_title,requirement_id,case_precontion,case_step,case_expected_result,case_type,case_status,case_priority,case_created_by,case_actual_result] return row #修改用例类型 def get_execution_type(topics): labels=[topic.get(‘label’, ”) for topic in topics] labels=filter_empty_or_ignore_element(labels) exe_type=1 for item in labels[::-1]: if item.lower() in [‘性能测试’, ‘性能’]: exe_type=2 break if item.lower() in [‘功能测试’, ‘功能’]: exe_type=1 break if item.lower() in [‘安全测试’, ‘安全’,’安全性测试’]: exe_type=3 break if item.lower() in [‘其他’]: exe_type=4 break return exe_type