zentao.py
源码修改部分
1、修改优先级部分,找到zentao.py,修改以下方法
def gen_case_priority(priority):
# 修改前
# mapping = {1: '高', 2: '中', 3: '低'}
# 修改后
mapping = {1: '1', 2: '2', 3: '3', 4: '4'}
if priority in mapping.keys():
return mapping[priority]
else:`
# 修改前
return '中'
# 修改后
return '2'
2.修改用例类型部分,修改zentao.py,修改此以下方法
def gen_case_type(case_type):
# 修改前
# mapping = {1: '手动', 2: '自动'}
# 修改后
mapping = {1: '功能测试', 2: '其他测试'}
if case_type in mapping.keys():
return mapping[case_type]
else:
# 修改前
# return '手动'
# 修改后
return '功能测试'
3.修改适应阶段部分,修改zentao.py,修改以下方法
def gen_a_testcase_row(testcase_dict):
case_module = gen_case_module(testcase_dict['suite'])
case_title = testcase_dict['name']
case_precontion = testcase_dict['preconditions']
case_step, case_expected_result = gen_case_step_and_expected_result(testcase_dict['steps'])
case_keyword = ''
case_priority = gen_case_priority(testcase_dict['importance'])
case_type = gen_case_type(testcase_dict['execution_type'])
# 修改前
# case_apply_phase = '迭代测试'
# 修改后
case_apply_phase = '系统测试阶段'
row = [case_module, case_title, case_precontion, case_step, case_expected_result, case_keyword, case_priority,
case_type, case_apply_phase]
return row
4.导出文件有空行,修改zentao.py,修改一下方法xmind_to_zentao_csv_file ,写入方法增加newline=''
# 修改前
# with open(zentao_file, 'w', encoding='utf8') as f:
# 修改后
with open(zentao_file, 'w', encoding='utf8', newline='') as f:
5.用例步骤、预期结果序号后多一个空格,修改zentao.py,修改一下方法
def gen_case_step_and_expected_result(steps):
case_step = ''
case_expected_result = ''
# 修改后,把+ '. ' + 后的空格去掉 + '.' +
for step_dict in steps:
case_step += str(step_dict['step_number']) + '.' + step_dict['actions'].replace('\n', '').strip() + '\n'
case_expected_result += str(step_dict['step_number']) + '.' + \
step_dict['expectedresults'].replace('\n', '').strip() + '\n' \
6、每导出一个测试用例步骤和预期结果会多一个换行符,修改zentao.py中以下方法
def gen_case_step_and_expected_result(steps):
case_step = ''
case_expected_result = ''
# 修改后,把+ '. ' + 后的空格去掉 + '.' +
for step_dict in steps:
case_step += str(step_dict['step_number']) + '.' + step_dict['actions'].replace('\n', '').strip() + '\n'
case_expected_result += str(step_dict['step_number']) + '.' + \
step_dict['expectedresults'].replace('\n', '').strip() + '\n' \
if step_dict.get('expectedresults', '') else ''
# 添加,去除每个单元格里最后一个换行符
case_step = case_step.rstrip('\n')
case_expected_result = case_expected_result.rstrip('\n')
return case_step, case_expected_result
#去除最后一个换行符
7、填写默认关键词,修改zentao.py中以下方法即可
def gen_a_testcase_row(testcase_dict):
case_module = gen_case_module(testcase_dict['suite'])
case_title = testcase_dict['name']
case_precontion = testcase_dict['preconditions']
case_step, case_expected_result = gen_case_step_and_expected_result(testcase_dict['steps'])
# 此处可填写默认关键词
case_keyword = ''
8、去掉用例标题中的空格,修改parser.py修改以下方法即可
def gen_testcase_title(topics):
"""Link all topic's title as testcase title"""
titles = [topic['title'] for topic in topics]
titles = filter_empty_or_ignore_element(titles)
# when separator is not blank, will add space around separator, e.g. '/' will be changed to ' / '
separator = config['sep']
if separator != ' ':
# 修改前
# separator = ' {} '.format(separator)
# 修改后
separator = f'{separator}'
return separator.join(titles)