introduction
Before long, I wrote an article about HTMLTestRunner report optimization process: https://www.cnblogs.com/liudinglong/p/12346824.html , behind the Friends group asked a question in the group, is on the adoption of and problem cases, style icon and click response with failure. Although long ago have helped the group Friends resolved, due to the busy before, but has not been written down, write it down now, in order to help more small partners detours.
problem
Here is the group Friends of the question:
Friends said the group did not approach my blog on the subject, well, take a look at what the problem is:
Screenshot for group of friends and found two problems:
One problem: the location is not pie-friendly
Question two: Click through no reaction, or after clicking through, it did not show the log.
solution
First, enter the report template source code, find the report _generate_report_test, as follows:
def _generate_report_test(self, rows, cid, tid, n, t, o, e): # e.g. 'pt1.1', 'ft1.1', etc has_output = bool(o or e) # ID修改点为下划线,支持Bootstrap折叠展开特效 - Findyou tid = (n == 0 and 'p' or 'f') + 't%s_%s' % (cid+1,tid+1) name = t.id().split('.')[-1] if self.verbosity > 1: doc = t.shortDescription() or "" else: doc = "" desc = doc and ('%s: %s' % (name, doc)) or name if not PY3K: if isinstance(desc, str): desc = desc.decode("utf-8") # tmpl = has_output and self.REPORT_TEST_WITH_OUTPUT_TMPL or self.REPORT_TEST_NO_OUTPUT_TMPL tmpl = has_output and (n==0 and self.REPORT_TEST_NO_OUTPUT_TMPL or self.REPORT_TEST_WITH_OUTPUT_TMPL) or self.REPORT_TEST_NO_OUTPUT_TMPL # utf-8 支持中文 - Findyou # o and e should be byte string because they are collected from stdout and stderr? if isinstance(o, str): # uo = unicode(o.encode('string_escape')) if PY3K: uo = o else: uo = o.decode('utf-8', 'ignore') else: uo = o if isinstance(e, str): # ue = unicode(e.encode('string_escape')) if PY3K: ue = e elif e.find("Error") != -1 or e.find("Exception") != -1: es = e.decode('utf-8', 'ignore').split('\n') es[-2] = es[-2].decode('unicode_escape') ue = u"\n".join(es) else: ue = e.decode('utf-8', 'ignore') else: ue = e script = self.REPORT_TEST_OUTPUT_TMPL % dict( id=tid, output=saxutils.escape(uo + ue), ) if getattr(t, 'imgs', []): # 判断截图列表,如果有则追加 tmp = u"" for i, img in enumerate(t.imgs): if i == 0: tmp += """ <img src="data:image/jpg;base64,%s" style="display: block;" class="img"/>\n""" % img else: tmp += """ <img src="data:image/jpg;base64,%s" style="display: none;" class="img"/>\n""" % img imgs = self.IMG_TMPL % dict(imgs=tmp) else: imgs = u"""无截图""" row = tmpl % dict( tid=tid, Class=(n == 0 and 'hiddenRow' or 'none'), style=n == 2 and 'errorCase' or (n == 1 and 'failCase' or 'passCase'), desc=desc, script=script, status=self.STATUS[n], img=imgs, ) rows.append(row) if not has_output: return def _generate_ending(self): return self.ENDING_TMPL
This function is mainly treated if test results show on the report, the whole do not understand it does not matter, just add code:
n == 2 embodiment is adopted, outputs REPORT_TEST_WITH_OUTPUT_TMPL, otherwise the output REPORT_TEST_NO_OUTPUT_TMPL,
The contents of REPORT_TEST_NO_OUTPUT_TMPL been changed and REPORT_TEST_WITH_OUTPUT_TMPL, then button rendered as: btn-success.
Then there is a pie chart, modify the position:
Report optimized
After optimization, we then run the script to view the report:
Reply group Friends of the screenshot:
Since then, HTML optimization report concludes. In addition, like automation, test development partners can join our small learning exchange QQ group: 696 400 122.