04、產生 HTMLTestRunner 測試報告

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   使用   sp   

1、HTMLTestRunner 是 Python 標準庫的 unittest 模組的一個擴充。它產生便於使用的HTML 測試報告
1>下載HTMLTestRunner.py檔案,地址為:
http://tungwaiyip.info/software/HTMLTestRunner.html
Windows平台:將下載的檔案放入...\Python27\Lib 目錄下Linux平台:下需要先確定 python 的安裝目錄,開啟終端,輸入 python 命令進入 python 互動模式,通過sys.path 可以查看本機 python 檔案目錄,以管理員身份將 HTMLTestRunner.py檔案考本到/usr/lib/python2.7/dist-packages/ 目錄下
2>匯入模組:import HTMLTestRunner。在代碼最尾部編寫代碼:






更好用的HTML報告

替換附件中的HTMLTestRunner.py。關於HTML報告中顯示出的方法在HTMLTestRunner中已經寫死,所以必須按寫死的路徑來設定檔案件。檔案夾順序如下:
對HTMLTestRunner中的總結如下:1、設定HTML報告的存放路徑為result2、設定儲存的路徑為result\image\。3、data裡面的圖片用來做表徵圖4、在代碼裡面把路徑給列印出來,具體效果如下:
  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, "wb")
  14. runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"百度測試報告", description=u"用例測試情況")
  15. runner.run(testunit)




























來自為知筆記(Wiz)

附件列表

     

    04、產生 HTMLTestRunner 測試報告

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.