1. Htmltestrunner is an extension of the UnitTest module of the Python Standard library. It generates easy-to-use HTML test reports
1> Download the htmltestrunner.py file with the address:
http://tungwaiyip.info/software/HTMLTestRunner.html
Windows platform:
put the downloaded file in the ... \python27\lib directory
Linux Platforms
:
need to determine the Python installation directory, open the terminal, enter the python command into the Python interactive mode, through Sys.path can view the native Python file directory, as an administrator to the htmltestrunner.py file to/usr Under the/lib/python2.7/dist-packages/directory
2> Importing module:importHtmltestrunner. Write code at the tail end of the code:
better use of HTML reports
Replace the htmltestrunner.py in the attachment. The method shown in the HTML report has been written dead in Htmltestrunner, so the file must be set according to the path of the write dead. The folder order is as follows:
The summary of the Htmltestrunner is as follows: 1, the setting of the HTML report is RESULT2, set the path to save result\image\. 3, the data inside the image used to do the icon 4, in the code to print out the path, the specific effect is as follows:
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest
import time,sys
import HTMLTestRunner
reload(sys)
sys.setdefaultencoding("utf-8")
class Baidu(unittest.TestCase):
"""百度首页搜索测试用例"""
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com"
def test_baidu_search(self):
driver = self.driver
print u"========【case_0001】 百度搜索============="
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys(u"林志玲")
driver.find_element_by_id("su").click()
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
#必须要打印路径HTMLTestRunner才能捕获并且生成路径,\image\**.png 是获取路径的条件,必须这样的目录
pic_path=‘..\\result\\image\\‘+now+‘.png‘
print pic_path
driver.save_screenshot(pic_path)
time.sleep(2)
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_baidu_search"))
HtmlFile = "..\\result\\"+now+"HTMLtemplate.html"
print HtmlFile
FP = file ( Htmlfile "WB" )
runner = htmltestrunner . htmltestrunner ( stream = FP title = u "Baidu Test Report" description = u "use case test Case" )
runner.run(testunit)
From for notes (Wiz)
List of attachments
04. Generate Htmltestrunner Test Report