예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
파일: cli.py 프로젝트: Jinggit/xmind2devops
def cli_main():
    if len(sys.argv) > 1 and sys.argv[1].endswith('.xmind'):
        xmind_file = sys.argv[1]
        xmind_file = get_absolute_path(xmind_file)
        logging.info('Start to convert XMind file: %s', xmind_file)

        if len(sys.argv) == 3 and sys.argv[2] == '-csv':
            devops_csv_file = xmind_to_devops_csv_file(xmind_file)
            devops_csv_file = final_fix_csv_file(devops_csv_file)
            logging.info(
                'Convert XMind file to devops csv file successfully: %s',
                devops_csv_file)
        else:
            devops_csv_file = xmind_to_devops_csv_file(xmind_file)
            devops_csv_file = final_fix_csv_file(devops_csv_file)
            logging.info(
                'Convert XMind file successfully: \n'
                'devops csv file(%s)', devops_csv_file)
    elif len(sys.argv) > 1 and sys.argv[1] == 'webtool':
        if len(sys.argv) == 3:
            try:
                port = int(sys.argv[2])
                launch(port=port)
            except ValueError:
                launch()
        else:
            launch()

    else:
        print(using_doc)
예제 #5
0
def xmind_to_testlink_xml_file(xmind_file, is_all_sheet=True):
    """Convert a XMind sheet to a testlink xml file"""
    xmind_file = get_absolute_path(xmind_file)
    logging.info('Start converting XMind file(%s) to testlink file...',
                 xmind_file)
    testsuites = get_xmind_testsuites(xmind_file)
    if not is_all_sheet and testsuites:
        testsuites = [testsuites[0]]

    xml_content = testsuites_to_xml_content(testsuites)
    testlink_xml_file = xmind_file[:-6] + '.xml'

    if os.path.exists(testlink_xml_file):
        logging.info(
            'the testlink xml file already exists, return it directly: %s',
            testlink_xml_file)
        return testlink_xml_file

    with open(testlink_xml_file, 'w', encoding='utf-8') as f:
        pretty_content = minidom.parseString(xml_content).toprettyxml(
            indent='\t')
        f.write(pretty_content)
        logging.info(
            'convert XMind file(%s) to a testlink xml file(%s) successfully!',
            xmind_file, testlink_xml_file)

    return testlink_xml_file
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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
예제 #9
0
def cli_main():
    if len(sys.argv) > 1 and sys.argv[1].endswith('.xmind'):
        xmind_file = sys.argv[1]
        xmind_file = get_absolute_path(xmind_file)
        logging.info('Start to convert XMind file: %s', xmind_file)

        if len(sys.argv) == 3 and sys.argv[2] == '-json':
            testlink_json_file = xmind_testcase_to_json_file(xmind_file)
            logging.info(
                'Convert XMind file to testcase json file successfully: %s',
                testlink_json_file)
        elif len(sys.argv) == 3 and sys.argv[2] == '-xml':
            testlink_xml_file = xmind_to_testlink_xml_file(xmind_file)
            logging.info(
                'Convert XMind file to testlink xml files successfully: %s',
                testlink_xml_file)
        elif len(sys.argv) == 3 and sys.argv[2] == '-csv':
            zentao_csv_file = xmind_to_zentao_csv_file(xmind_file)
            logging.info(
                'Convert XMind file to zentao csv file successfully: %s',
                zentao_csv_file)
        else:
            testlink_json_file = xmind_testcase_to_json_file(xmind_file)
            testlink_xml_file = xmind_to_testlink_xml_file(xmind_file)
            zentao_csv_file = xmind_to_zentao_csv_file(xmind_file)
            logging.info(
                'Convert XMind file successfully: \n'
                '1、 testcase json file(%s)\n'
                '2、 testlink xml file(%s)\n'
                '3、 zentao csv file(%s)', testlink_json_file,
                testlink_xml_file, zentao_csv_file)
    elif len(sys.argv) > 1 and sys.argv[1] == 'webtool':
        if len(sys.argv) == 3:
            try:
                port = int(sys.argv[2])
                launch(port=port)
            except ValueError:
                launch()
        else:
            launch()

    else:
        print(__doc__)
        logging.error('%s', __doc__)
예제 #10
0
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
예제 #11
0
def xmind_to_qqtestcase_file(xmind_file):
    """Convert XMind file to a qqtestcase file"""
    xmind_file = get_absolute_path(xmind_file)
    logging.info('Start converting XMind file(%s) to qqtestcase file...',
                 xmind_file)
    testsutie_dict = get_xmind_testcase_list_dict(xmind_file)

    fileheader = ["编号", "功能模块", "测试点", "前置条件", "操作步骤", "预期结果"]

    qqtestcase_file = xmind_file[:-6] + '_qq' + '.xlsx'

    if os.path.exists(qqtestcase_file):
        logging.info(
            'The qqtestcase file already exists, return it directly: %s',
            qqtestcase_file)
        return qqtestcase_file

    workbook = xlsxwriter.Workbook(qqtestcase_file)

    # 自动换行
    style_text_wrap = 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列写入内容

    smoke_case_dict = {}
    for product in testsutie_dict:

        smoke_case_dict[product] = []

        sheet = workbook.add_worksheet(product)  #sheet名
        sheet.set_column("A:B", 15)
        sheet.set_column("C:F", 30)

        # 用例title
        sheet.write(0, 0, fileheader[0])
        sheet.write(0, 1, fileheader[1])
        sheet.write(0, 2, fileheader[2])
        sheet.write(0, 3, fileheader[3])
        sheet.write(0, 4, fileheader[4])
        sheet.write(0, 5, fileheader[5])

        #第二行开始写入用例
        case_index = 1
        case_no = 0
        for testcase in testsutie_dict[product]:
            row_dict = gen_a_testcase_row_dict(testcase)  #包含用例信息
            row_list = row_dict["case_row_list"]  #取用例列
            # print("row_dict", row_dict)

            #####################
            smoke_case = {}
            if row_dict["case_priority"] == "高":
                smoke_case["module"] = row_dict["case_module"]
                smoke_case["name"] = row_dict["case_title"]
                smoke_case["precontion"] = row_dict["case_precontion"]
                smoke_case["case"] = []

            ##########################

            for row in row_list:
                if len(row[1]) > 0:
                    case_no += 1
                    sheet.write(case_index, 0, "No." + str(case_no),
                                style_text_wrap)
                else:
                    sheet.write(case_index, 0, "", style_text_wrap)

                sheet.write(case_index, 1, row[0], style_text_wrap)
                sheet.write(case_index, 2, row[1], style_text_wrap)
                sheet.write(case_index, 3, row[2], style_text_wrap)
                sheet.write(case_index, 4, row[3], style_text_wrap)
                sheet.write(case_index, 5, row[4], style_text_wrap)
                case_index = case_index + 1

                #给用例加操作步骤 预期结果
                if len(smoke_case) > 0:
                    smoke_case["case"].append([row[3], row[4]])

            if len(smoke_case) > 0:
                smoke_case_dict[product].append(smoke_case)
    # print(smoke_case_dict)

    #写入冒烟测试
    #############
    if len(smoke_case_dict) > 0:
        sheet2 = workbook.add_worksheet("冒烟用例")  # sheet名
        sheet2.set_column("A:A", 15)
        sheet2.set_column("B:B", 80)

        _case_index = 0
        #分解sheet
        for product in smoke_case_dict:
            if len(smoke_case_dict[product]) > 0:
                # 用例title
                sheet2.write(_case_index, 0, "编号", style_text_wrap)
                sheet2.write(_case_index, 1, "%s 冒烟用例" % product,
                             style_text_wrap)
                _case_index += 1
                _smoke_case_list = smoke_case_dict[product]
                _case_no = 0
                for _smoke_case in _smoke_case_list:
                    _smoke_case_string = "测试点:\n"
                    _smoke_case_string += _smoke_case["name"] + "\n\n"
                    # print("_smoke_case", _smoke_case)
                    #前置条件
                    if len(_smoke_case["precontion"]
                           ) > 0 and _smoke_case["precontion"] != '无':
                        _smoke_case_string += "前置条件:\n"
                        _smoke_case_string += _smoke_case["precontion"] + "\n\n"
                    _step_index = 0
                    for _step in _smoke_case["case"]:
                        if len(_step[0]) > 0 and len(_step[1]):
                            _step_index += 1
                            _smoke_case_string += "操作步骤" + str(
                                _step_index) + ":\n"
                            _smoke_case_string += _step[0] + "\n\n"
                            _smoke_case_string += "预期结果" + str(
                                _step_index) + ":\n"
                            _smoke_case_string += _step[1] + "\n\n"
                        elif len(_step[0]) > 0:
                            _step_index += 1
                            _smoke_case_string += "操作步骤" + str(
                                _step_index) + ":\n"
                            _smoke_case_string += _step[0] + "\n\n"

                    # print(_smoke_case_string)
                    _case_no += 1
                    sheet2.write(_case_index, 0, "No." + str(_case_no),
                                 style_text_wrap)
                    sheet2.write(_case_index, 1, _smoke_case_string,
                                 style_text_wrap)
                    _case_index += 1
                _case_index += 1

    ###################
    workbook.close()
    logging.info(
        'Convert XMind file(%s) to a qqtestcase file(%s) successfully!',
        xmind_file, qqtestcase_file)

    return qqtestcase_file
예제 #12
0
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