def handle_test_end(self, passed): '''处理一个测试用例执行的结束 :param passed: 测试用例是否通过 :type passed: boolean ''' self._testnode.setAttribute('result', str(passed)) self._testnode.setAttribute('endtime', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.end_time))) self._testnode.setAttribute('duration', "%02d:%02d:%02.2f\n" % _convert_timelength(self.end_time - self.begin_time)) if self._file_path: with codecs_open(smart_text(self._file_path), 'wb') as fd: fd.write(to_pretty_xml(self._xmldoc))
def end_report(self): '''结束测试执行 :param passed: 测试是否通过 :type passed: boolean ''' time_end = datetime.now() timexml = "<RunTime><StartTime>%s</StartTime><EndTime>%s</EndTime><Duration>%s</Duration></RunTime>" timexml = timexml % (self._time_start.strftime("%Y-%m-%d %H:%M:%S"), time_end.strftime("%Y-%m-%d %H:%M:%S"), str(time_end - self._time_start).split('.')[0]) timenodes = dom.parseString(timexml) self._runrstnode.appendChild(timenodes.childNodes[0]) xmldata = to_pretty_xml(self._xmldoc) with codecs_open('TestReport.xml', 'wb') as fd: fd.write(xmldata) test_repor_xsl = get_inner_resource("qta_statics", "TestReport.xsl") shutil.copy(test_repor_xsl, os.getcwd()) test_result_xsl = get_inner_resource("qta_statics", "TestResult.xsl") shutil.copy(test_result_xsl, os.getcwd())
def toxml(self): '''返回xml文本 :returns string - xml文本 ''' return to_pretty_xml(self._xmldoc)