解析Xmind转成用例

from xmindparser import xmind_to_dict
class ParserXmind:
    def __init__(self,xmind_path):
        self.xmind_path = xmind_to_dict(xmind_path)[0]
        # 分割标识
        self.flag = '=>'
        # 解析结果
        self.parser_result = {}
        self.paserXmind()
    def parserTestCase(self,Case):
        res = {}
        for param in Case:
            k = param.get("title")
            v = param.get("topics")[0].get("title")
            res.update({k: v})
        return res
    def paserXmind(self,parser_dict=None,parent_dir=''):
        k = parser_dict or self.xmind_path
        title = k.get('title')
        topic = k.get('topic')
        topics = k.get('topics')
        parent_dir = f"{parent_dir}{self.flag}{title}"
        if topic:
            self.paserXmind(topic,  parent_dir)
        if topics:
            for x in topics:
                self.paserXmind(x,  parent_dir)
        if title == 'TestCase':
            parent_dir = f'{parent_dir}{self.flag}{topics[0].get("title")}'
            parent_dir = parent_dir.strip(f'{self.flag}')
            vv = self.parserTestCase(topics[0].get("topics"))
            self.parser_result.update({parent_dir: vv})
if __name__ == '__main__':
    print(ParserXmind(r'C:\Users\80640\Desktop\链接、事务响应时间过长.xmind').parser_result)







上一篇:TabletLayout 数据库


下一篇:源码分析zookeeper在kafka的作用