Android CTS 错误报告提取脚本

Android 8.0 的系统CTS 测试报告动辄就是60-70M,浏览器打开太慢了,不利于工程师查看报告。所以简单写了一个python 脚本只提取所有错误的报告信息。主要使用ptyhon 的xpath 技术实现。

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# owner zhouyong0701 2018/01/16
from lxml import etree


def sperate():
    tree = etree.parse("./test_result.xml")
    # moudules= tree.xpath('/Result/Module')
    # for moudule in moudules:
    #     print moudule.xpath('./@*')[0]
    result_file = open("./test_result.xml")
    fail_file = open('test_result_fail_report.xml', 'w')
    line = result_file.readline()
    while line:
        if "<Module" in line:
            break
        fail_file.write(line)
        line = result_file.readline()

    result_file.close()


    moudules = tree.xpath('/Result/Module')
    total = 0;
    fail = 0;
    #foreache moudule
    for moudule in moudules:
        fail_tests = moudule.xpath('.//Test[@result="fail"]')
        if len(fail_tests) > 0 :
            print "parser moudule -> " + moudule.xpath('./@name')[0] + " fail -> " + str(len(fail_tests))
            #print etree.tostring(moudule)
            total += 1
            fail += len(fail_tests)
            testcases = moudule.xpath('./TestCase')
            #foreach TestCase remove the all pass TestCase from moudule
            for testcase in testcases:
                fail_count = testcase.xpath('.//Test[@result="fail"]')
                if len(fail_count) == 0 :
                    moudule.remove(testcase)
                pass_count = testcase.xpath('.//Test[@result="pass"]')
                if len(pass_count) > 0 :
                    tests = testcase.xpath('./Test')
                    #foreach test remove the pass test in TestCase
                    for test in tests :
                        if test.xpath('./@result')[0] == 'pass' :
                            print "remove test -> " + test.xpath('./@name')[0] + " = " + test.xpath('./@result')[0]
                            testcase.remove(test)

            fail_file.write(etree.tostring(moudule))
    print "total moudules: " + str(total) + " fail : " + str(fail)
    fail_file.write("</Result>\n");
    fail_file.close()

def main():
    sperate();


if __name__ == '__main__':
    main();

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值