To generate Htmltestrunner test reports

Source: Internet
Author: User

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 reportsReplace 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 Htmltestrunner is as follows: 1, set the location of the HTML report to RESULT2, set the saved path to 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:
  1. # -*- coding: utf-8 -*-
  2. from selenium import webdriver
  3. import unittest
  4. import time,sys
  5. import HTMLTestRunner
  6. reload(sys)
  7. sys.setdefaultencoding("utf-8")
  8. class Baidu(unittest.TestCase):
  9. """百度首页搜索测试用例"""
  10. def setUp(self):
  11. self.driver = webdriver.Chrome()
  12. self.driver.implicitly_wait(30)
  13. self.base_url = "http://www.baidu.com"
  14. def test_baidu_search(self):
  15. driver = self.driver
  16. print u"========【case_0001】 百度搜索============="
  17. driver.get(self.base_url + "/")
  18. driver.find_element_by_id("kw").clear()
  19. driver.find_element_by_id("kw").send_keys(u"林志玲")
  20. driver.find_element_by_id("su").click()
  21. now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
  22. #必须要打印路径HTMLTestRunner才能捕获并且生成路径,\image\**.png 是获取路径的条件,必须这样的目录
  1. pic_path=‘..\\result\\image\\‘+now+‘.png‘
  2. print pic_path
  3. driver.save_screenshot(pic_path)
  4. time.sleep(2)
  5. def tearDown(self):
  6. self.driver.quit()
  7. if __name__ == "__main__":
  8. now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
  9. testunit = unittest.TestSuite()
  10. testunit.addTest(Baidu("test_baidu_search"))
  11. HtmlFile = "..\\result\\"+now+"HTMLtemplate.html"
  12. print HtmlFile
  13. FP = File (htmlfile, )
  14. runner = htmltestrunner. Htmltestrunner (stream=FP , Title=u "Baidu Test Report" Span class= "pun" >, Description=u "use case test Case" /span>
  15. runner.run(testunit)

To generate Htmltestrunner test reports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.