def _build_xml(self, r, d): if isinstance(d, dict): for k, v in d.items(): s = SE(r, k) self._build_xml(s, v) elif isinstance(d, (tuple, list)): for v in d: s = SE(r, 'i') self._build_xml(s, v) else: r.text = str(d) return r
def mergeLogs(fromFilePath, toFilePath, outputFilePath): utf8open = lambda s: open(s, 'r', 'utf8') outputDoc = E('html') with utf8open(fromFilePath) as fromFile, utf8open(toFilePath) as toFile: # the body and HTML tags are left open so the app can just append # when a new message comes in. we have to close them. # note: this could also be taken care of by BeautifulSoup or # perhaps lxml.html fromDoc = fromstring(fromFile.read() + '</BODY></HTML>') toDoc = fromstring(toFile.read() + '</BODY></HTML>') # copy the head tag so formatting and stuff is preserved in our new doc outputDoc.append(fromDoc.find('HEAD').copy()) fromMessages = fromDoc.findall('./BODY/div') toMessages = toDoc.findall('./BODY/div') allMessages = list(fromMessages) + list(toMessages) allMessages.sort(key=lambda e: time.strptime(e.attrib['timestamp'], '%Y-%m-%d %H:%M:%S')) body = SE(outputDoc, 'BODY', attrib=fromDoc.find('BODY').attrib) body.extend(x.copy() for x in allMessages) ElementTree(outputDoc).write(outputFilePath, 'utf8')
def genSummaryXml(): try: tree = ElementTree() root = Element("result_summary", {"plan_name": ""}) tree._setroot(root) env = SE( root, "environment", { "build_id": "", "cts_version": "", "device_id": "", "device_model": "", "device_name": "", "host": "", "resolution": "", "screen_size": "", "manufacturer": "" }) summary = SE(root, "summary") startTime = SE(summary, "start_at") endTime = SE(summary, "end_at") startTime.text = Start endTime.text = End suite = SE(root, "suite", {"name": "wrt-packertool-android-tests"}) total_case = SE(suite, "total_case") total_case.text = str(totalNum) pass_case = SE(suite, "pass_case") pass_case.text = str(passNum) pass_rate = SE(suite, "pass_rate") pass_rate.text = str(float(passNum) / totalNum * 100) fail_case = SE(suite, "fail_case") fail_case.text = str(failNum) fail_rate = SE(suite, "fail_rate") fail_rate.text = str(float(failNum) / totalNum * 100) SE(suite, "block_case") SE(suite, "block_rate") SE(suite, "na_case") SE(suite, "na_rate") tree.write(ConstPath + "/report/summary.xml") updateXmlTitle( ConstPath + "/report/summary.xml", '<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/summary.xsl"?>\n' ) print "Generate summary.xml file ------------------------->O.K" except Exception, e: print Exception, "Generate summary.xml error:", e
def genResultXml(): try: tree = ElementTree() root = Element("test_definition") tree._setroot(root) env = Element("environment", {"build_id":"","device_id":"","device_name":"","host":"",\ "lite_version":"","manufacturer":"","resolution":"","screen_size":""}) root.append(env) #summary element summary = Element("summary", {"test_plan_name": ""}) root.append(summary) tStart = SE(summary, "start_at") tEnd = SE(summary, "end_at") tStart.text = Start tEnd.text = End #suite element suite = SE(root, "suite", {"category":"Crosswalk_Packer_Tool","launcher":"xwalk",\ "name":"wrt-packertool-android-tests"}) setPositive = SE(suite, "set", { "name": "positive", "set_debug_msg": "" }) setNegitive = SE(suite, "set", { "name": "negitive", "set_debug_msg": "" }) #testcase element for case in ResultList: setElement = setPositive if case["set"] == "negative": setElement = setNegitive pur = "Check if packer tool work properly" testcase = SE(setElement, "testcase", {"component":"Crosswalk Packer Tool",\ "execution_type":"auto","id":case["id"],"purpose":pur,"result":case["result"]},) desc = SE(testcase, "description") entry = Element("test_script_entry") entry.text = "pack command: " + case["entry"].decode("utf-8") desc.append(entry) resultInfo = SE(testcase, "result_info") actualResult = SE(resultInfo, "actual_result") actualResult.text = case["result"] caseStart = SE(resultInfo, "start") caseStart.text = case["start"] caseEnd = SE(resultInfo, "end") caseEnd.text = case["end"] SE(resultInfo, "stdout") SE(resultInfo, "stderr") tree.write(ConstPath + "/report/wrt-packertool-android-tests.xml") updateXmlTitle( ConstPath + "/report/wrt-packertool-android-tests.xml", '<?xml version="1.0" encoding="UTF-8"?>\n<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>\n<?xml-stylesheet type="text/xsl" href="testresult.xsl"?>\n' ) print "Generate test.result.xml file ------------------------->O.K" except Exception, e: print Exception, "Generate test.result.xml error:", e