Android CTSエラーレポート抽出スクリプト


Android 8.0のシステムCTSテストレポートは、60-70 Mになりがちです.ブラウザの開きが遅すぎて、エンジニアがレポートを表示するのに不利です.したがって、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 " 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("
"); fail_file.close() def main(): sperate(); if __name__ == '__main__': main();