def xmind_to_excel_csv_file(xmind_file): """Convert XMind file to a excel csv file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to excel file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = [ "所属模块", "用例标题", "前置条件", "步骤", "预期", "关键词", "优先级", "用例类型", "适用阶段" ] excel_testcase_rows = [fileheader] for testcase in testcases: row = gen_a_testcase_row(testcase) excel_testcase_rows.append(row) excel_file = xmind_file[:-6] + '_excel' + '.csv' if os.path.exists(excel_file): logging.info( 'The excel csv file already exists, return it directly: %s', excel_file) return excel_file with open(excel_file, 'w', newline="") as f: writer = csv.writer(f) writer.writerows(excel_testcase_rows) logging.info( 'Convert XMind file(%s) to a excel csv file(%s) successfully!', xmind_file, excel_file) return excel_file
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) fileheader = [ "所属模块", "用例类型", "相关需求", "用例标题", "优先级", "前置条件", "步骤", "预期", "关键词", "用例状态" ] zentao_testcase_rows = [fileheader] for testcase in testcases: row = gen_a_testcase_row(testcase) zentao_testcase_rows.append(row) zentao_file = xmind_file[:-6] + '.csv' if os.path.exists(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='gbk', newline='' ) as f: # fengtao 1,modify encoding to GBK 2,add paremater newline='' 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
def xmind(case_type="testcase_json"): case_type_define = ["json", "zentao_csv", "testlink_xml", "testsuite_json", "testsuites", "testcase_json", "testcases"] xmind_file = 'static/files/BOOT3X_V3.9.0_V2.19.0.xmind' logger.info('Start to convert XMind file: %s' % xmind_file) if case_type == "testcase_json": testcase_json_file = xmind_testcase_to_json_file(xmind_file) logger.info('Convert XMind file to testcase json file successfully: %s', testcase_json_file) elif case_type == "zentao_csv": zentao_csv_file = xmind_to_zentao_csv_file(xmind_file) logger.info('Convert XMind file to zentao csv file successfully: %s', zentao_csv_file) elif case_type == "testlink_xml": testlink_xml_file = xmind_to_testlink_xml_file(xmind_file) logger.info('Convert XMind file to testlink xml file successfully: %s', testlink_xml_file) elif case_type == "testsuite_json": testsuite_json_file = xmind_testsuite_to_json_file(xmind_file) logger.info('Convert XMind file to testsuite json file successfully: %s', testsuite_json_file) elif case_type == "testsuites": testsuites = get_xmind_testsuite_list(xmind_file) logger.info('Convert XMind to testsuits dict data:\n%s',json.dumps(testsuites, indent=2, separators=(',', ': '), ensure_ascii=False)) elif case_type == "testcases": testcases = get_xmind_testcase_list(xmind_file) logger.info('Convert Xmind to testcases dict data:\n%s', json.dumps(testcases, indent=4, separators=(',', ': '))) elif case_type == "json": xmind_file = 'xmind_testcase_template.xmind' workbook = xmind.load(xmind_file) logger.info('Convert XMind to Json data:\n%s', json.dumps(workbook.getData(), indent=2, separators=(',', ': '), ensure_ascii=False)) logger.info('Finished conversion, Congratulations!') return True
def xmind_to_iwork_csv_file(xmind_file): """Convert XMind file to a iwork csv file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to iwork file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = ["用例概要*", "用例描述", "测试步骤", "测试数据", "预期结果"] iwork_testcase_rows = [fileheader] for testcase in testcases: # row = gen_a_testcase_row(testcase) row_list = gen_a_testcase_row_list(testcase) # print("row_list >> ", row_list) for row in row_list: iwork_testcase_rows.append(row) iwork_file = xmind_file[:-6] + '_iwork' + '.csv' if os.path.exists(iwork_file): logging.info( 'The eiwork csv file already exists, return it directly: %s', iwork_file) return iwork_file with open(iwork_file, 'w', encoding='gb18030', newline="") as f: writer = csv.writer(f) writer.writerows(iwork_testcase_rows) logging.info( 'Convert XMind file(%s) to a iwork csv file(%s) successfully!', xmind_file, iwork_file) return iwork_file
def xmind_to_devops_csv_file(xmind_file): """Convert XMind file to a devops csv file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to devops file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = [ "ID", "Work Item Type", "Title", "Test Step", "Step Action", "Step Expected", "Revision", "Area Path", "Assigned To", "State" ] devops_testcase_rows = [fileheader] for testcase in testcases: row, row1 = gen_a_testcase_row(testcase) devops_testcase_rows.append(row) devops_testcase_rows.append(row1) devops_file = xmind_file[:-6] + '.csv' if os.path.exists(devops_file): os.remove(devops_file) # logging.info('The devops csv file already exists, return it directly: %s', devops_file) # return devops_file with open(devops_file, 'w', encoding='utf8', newline='') as f: writer = csv.writer(f) writer.writerows(devops_testcase_rows) logging.info( 'Convert XMind file(%s) to a devops csv file(%s) successfully!', xmind_file, devops_file) return devops_file
def xmind_to_iwork_excel_file(xmind_file): """Convert XMind file to a iwork excel file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to iwork file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = ["用例概要*", "用例描述", "测试步骤", "测试数据", "预期结果"] wbk = xlwt.Workbook() sheet1 = wbk.add_sheet('README', cell_overwrite_ok=True) sheet1.write(0, 0, '测试用例内容请至第二页查看') # 第0行第0列写入内容 sheet2 = wbk.add_sheet('测试用例', cell_overwrite_ok=False) # 用例title sheet2.write(0, 0, fileheader[0]) sheet2.write(0, 1, fileheader[1]) sheet2.write(0, 2, fileheader[2]) sheet2.write(0, 3, fileheader[3]) sheet2.write(0, 4, fileheader[4]) #第二行开始写入用例 case_index = 1 for testcase in testcases: # row = gen_a_testcase_row(testcase) row_list = gen_a_testcase_row_list(testcase) # print("row_list >> ", row_list) for row in row_list: # for i in range(0,len(row)): # sheet2.write(case_index, i, row[i]) sheet2.write(case_index, 0, row[0]) sheet2.write(case_index, 1, row[1]) sheet2.write(case_index, 2, row[2]) sheet2.write(case_index, 3, row[3]) sheet2.write(case_index, 4, row[4]) case_index = case_index + 1 iwork_file = xmind_file[:-6] + '_iwork' + '.xlsx' if os.path.exists(iwork_file): logging.info( 'The eiwork excel file already exists, return it directly: %s', iwork_file) return iwork_file if iwork_file: wbk.save(iwork_file) logging.info( 'Convert XMind file(%s) to a iwork excel file(%s) successfully!', xmind_file, iwork_file) return iwork_file
def preview_file(filename): full_path = join(app.config['UPLOAD_FOLDER'], filename) if not exists(full_path): abort(404) testsuites = get_xmind_testsuites(full_path) suite_count = 0 for suite in testsuites: suite_count += len(suite.sub_suites) testcases = get_xmind_testcase_list(full_path) return render_template('preview.html', name=filename, suite=testcases, suite_count=suite_count)
def xmind_to_excel_file(xmind_file): """Convert XMind file to a excel csv file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to excel file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = [ "所属模块", "用例标题", "前置条件", "步骤", "预期", "关键词", "优先级", "用例类型", "适用阶段" ] wbk = xlwt.Workbook() sheet1 = wbk.add_sheet('测试用例', cell_overwrite_ok=False) # 自动换行 style1 = xlwt.easyxf('align: wrap on, vert top') sheet1.col(0).width = 256 * 30 sheet1.col(1).width = 256 * 40 sheet1.col(2).width = 256 * 30 sheet1.col(3).width = 256 * 40 sheet1.col(4).width = 256 * 40 # 用例title for i in range(0, len(fileheader)): sheet1.write(0, i, fileheader[i]) #第二行开始写入用例 case_index = 1 for testcase in testcases: # row = gen_a_testcase_row(testcase) row = gen_a_testcase_row(testcase) # print("row_list >> ", row_list) for i in range(0, len(row)): sheet1.write(case_index, i, row[i], style1) case_index = case_index + 1 excel_file = xmind_file[:-5] + 'xls' if os.path.exists(excel_file): logging.info('The excel file already exists, return it directly: %s', excel_file) return excel_file if excel_file: wbk.save(excel_file) logging.info( 'Convert XMind file(%s) to a iwork excel file(%s) successfully!', xmind_file, excel_file) return excel_file
def main(): xmind_file = 'docs/xmind_testcase_template_v1.1.xmind' print('Start to convert XMind file: %s' % xmind_file) # 1、testcases import file # (1) zentao zentao_csv_file = xmind_to_zentao_csv_file(xmind_file) print('Convert XMind file to zentao csv file successfully: %s' % zentao_csv_file) # (2) testlink testlink_xml_file = xmind_to_testlink_xml_file(xmind_file) print('Convert XMind file to testlink xml file successfully: %s' % testlink_xml_file) # 2、 testcases json file # (1) testsuite testsuite_json_file = xmind_testsuite_to_json_file(xmind_file) print('Convert XMind file to testsuite json file successfully: %s' % testsuite_json_file) # (2) testcase testcase_json_file = xmind_testcase_to_json_file(xmind_file) print('Convert XMind file to testcase json file successfully: %s' % testcase_json_file) # 3、test dict/json data # (1) testsuite 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)) # (2) testcase testcases = get_xmind_testcase_list(xmind_file) print('Convert Xmind to testcases dict data:\n%s' % json.dumps( testcases, indent=4, separators=(',', ': '), ensure_ascii=False)) # (3) xmind file 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!')
def xmind(case_type="testcase_json"): case_type_define = [ "json", "zentao_csv", "testlink_xml", "testsuite_json", "testsuites", "testcase_json", "testcases" ] xmind_file = 'docs/xmind_testcase_template.xmind' print('Start to convert XMind file: %s' % xmind_file) if case_type == "testcase_json": testcase_json_file = xmind_testcase_to_json_file(xmind_file) print('Convert XMind file to testcase json file successfully: %s' % testcase_json_file) elif case_type == "zentao_csv": zentao_csv_file = xmind_to_zentao_csv_file(xmind_file) print('Convert XMind file to zentao csv file successfully: %s' % zentao_csv_file) elif case_type == "testlink_xml": testlink_xml_file = xmind_to_testlink_xml_file(xmind_file) print('Convert XMind file to testlink xml file successfully: %s' % testlink_xml_file) elif case_type == "testsuite_json": testsuite_json_file = xmind_testsuite_to_json_file(xmind_file) print('Convert XMind file to testsuite json file successfully: %s' % testsuite_json_file) elif case_type == "testsuites": 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)) elif case_type == "testcases": testcases = get_xmind_testcase_list(xmind_file) print('Convert Xmind to testcases dict data:\n%s' % json.dumps(testcases, indent=4, separators=(',', ': '))) elif case_type == "json": 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!')
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) # fileheader = ["所属模块", "用例标题", "前置条件", "步骤", "预期", "关键词", "优先级", "用例类型", "适用阶段"] fileheader = [ "所属模块", "相关需求", "用例标题", "前置条件", "优先级", "用例类型", "适用阶段", "步骤", "预期", "关键词", "用例状态" ] zentao_testcase_rows = [fileheader] for testcase in testcases: row = gen_a_testcase_row(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) # pdata = pd.read_csv(zentao_file) # zentao_xlsx_file = zentao_file[:-4] + '.xlsx' # if os.path.exists(zentao_xlsx_file): # os.remove(zentao_xlsx_file) # logging.info('The zentao csv file already exists, return it directly: %s', zentao_file) # return zentao_file # pdata.to_excel(zentao_xlsx_file, index=False) return zentao_file
def xmind_to_iwork_excel_file(xmind_file): """Convert XMind file to a iwork excel file""" xmind_file = get_absolute_path(xmind_file) logging.info('Start converting XMind file(%s) to iwork file...', xmind_file) testcases = get_xmind_testcase_list(xmind_file) fileheader = ["用例概要*", "用例描述", "测试步骤", "测试数据", "预期结果"] iwork_file = xmind_file[:-6] + '_iwork' + '.xlsx' if os.path.exists(iwork_file): logging.info( 'The eiwork excel file already exists, return it directly: %s', iwork_file) return iwork_file workbook = xlsxwriter.Workbook(iwork_file) # 红色字体 style1 = workbook.add_format({'font_color': '#FF0000'}) # 自动换行 style2 = workbook.add_format({'text_wrap': 1, 'valign': 'top'}) sheet1 = workbook.add_worksheet('README') sheet1.write(0, 0, '测试用例内容请至第二页查看') # 第0行第0列写入内容 sheet1.write(1, 0, '确认数量正确、内容正确后,可将此文件直接导入iWork系统', style1) # 第1行第0列写入内容 sheet2 = workbook.add_worksheet('测试用例') sheet2.set_column("A:E", 30) # 用例title sheet2.write(0, 0, fileheader[0]) sheet2.write(0, 1, fileheader[1]) sheet2.write(0, 2, fileheader[2]) sheet2.write(0, 3, fileheader[3]) sheet2.write(0, 4, fileheader[4]) #第二行开始写入用例 case_index = 1 for testcase in testcases: # row = gen_a_testcase_row(testcase) row_list = gen_a_testcase_row_list(testcase) # print("row_list >> ", row_list) for row in row_list: # for i in range(0,len(row)): # sheet2.write(case_index, i, row[i]) sheet2.write(case_index, 0, row[0], style2) sheet2.write(case_index, 1, row[1], style2) sheet2.write(case_index, 2, row[2], style2) sheet2.write(case_index, 3, row[3], style2) sheet2.write(case_index, 4, row[4], style2) # sheet2.set_row(case_index, len(row_list)*10) case_index = case_index + 1 workbook.close() logging.info( 'Convert XMind file(%s) to a iwork excel file(%s) successfully!', xmind_file, iwork_file) return iwork_file