For automation, test reports are required, and in an agile team, members of the team need to automate the test report to determine the overall quality of the system and the next Test strategy. The Unit Test library generates test output to the console window, but the results look more laborious, obviously, the output of the console log is not a good note, so the good note is to generate the test report of the HTML page, so the report looks clearer, fortunately UnitTest the htmltestrunner.py of the Unit Test Library extension , you can generate automated reports for HTML.
First, htmltestrunner.py
First, download the htmltestruner.py file.
Source address: http://tungwaiyip.info/software/HTMLTestRunner.html
This is for the Python2.7 version, so for python3.x use, Need to change a few places. Http://www.bubuko.com/infodetail-529431.html.
specific changes are as follows:
Line 94th, change import Stringio to import io
Line No. 539, Self.outputbuffer = Stringio.stringio () modified to self.outputbuffer= IO. Stringio ()
Line No. 631, change print >> sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime) to print ( Sys.stderr, ' \ntimeelapsed:%s '% (self.stoptime-self.starttime))
Line No. 642, if not Rmap.has_key (CLS): Modify to If Notcls in rmap:
Line No. 766, modify UO = O.decode (' latin-1 ') to UO = e
Line No. 775, change UE = E.decode (' latin-1 ') to UE = E &NBSP
Line No. 778, output = Saxutils.escape (Uo+ue), modified to output = Saxutils.escape (str (UO) +STR (UE)),
The above changes, save successfully, then put htmltestrunner.py into the C:\Python34\Lib directory, run cmd, enter Python, importing import Htmltestrunner, without any error message, indicates success, see:
htmltestrunner.py implementation of the HTML test report, see the following test instance code:
#coding: Utf-8
Fromselenium Import Webdriver
FromTime Import Sleep,time,ctime
Import UnitTest
FromPage Import *
Import threading
Import Htmltestrunner
Class Demopage (UnitTest. Testcase,basepage.page):
def setUp (self):
Self.driver=webdriver. Firefox ()
Self.driver.implicitly_wait (30)
Self.driver.maximize_window ()
Self.driver.get (' http://www.baidu.com ')
def testtitle (self,value= ' TestData '):
Self.asserttrue (Self.driver.title in Self.getxmldata (value))
def testurl (self):
Print Self.driver.current_url
def tearDown (self):
Self.driver.close ()
Self.driver.quit ()
if__name__== ' __main__ ':
Suite=unittest.makesuite (Demopage)
#定义自动化报告目录
Filename= ' d:\\git\\pycharm\\seleniumhq\\test-report\\report.html '
Fp=file (filename, ' WB ')
Runner=htmltestrunner.htmltestrunner (
STREAM=FP,
Title=u ' Automated test Report ',
Description=u ' Automated test Report '
)
Runner.run (Suite)
After successful execution, automated test reports in the D:\\git\\pycharm\\seleniumhq\\test-report directory report.html, open report.html files, you can see the following automated test reports:
Appium+python+htmltestrunner