selenium+python自動化91-unittest多線程產生報告(BeautifulReport)

來源:互聯網
上載者:User

標籤:python3   time   main   gpo   site   eal   __name__   efault   block   

前言

selenium多線程跑用例,這個前面一篇已經解決了,如何產生一個測試報告這個是痛點,剛好在github上有個大神分享了BeautifulReport,完美的結合起來,就能產生報告了。

環境必備:

  • python3.6 : BeautifulReport不支援2.7
  • tomorrow : pip install tomorrow安裝
  • BeautifulReport : github下載後放到/Lib/site-packages/目錄下
BeautifulReport

1.BeautifulReport:BeautifulReport

2.下載方法:

  • 方法一 會使用git的直接用git下載到本地

git clone https://github.com/TesterlifeRaymond/BeautifulReport

  • 方法二 點Clone or Download按鈕,Download ZIP就能下載到本地了

3.下載完之後,把BeautifulReport整個包放到python的/Lib/site-packages/目錄下

使用方法

1.項目結構:
case test開頭的.py用例指令碼
report 放產生的html報告
run_all.py 用於執行全部指令碼

2.單個測試指令碼test_a.py參考

# coding:utf-8import unittestfrom selenium import webdriverimport timeclass Testaa(unittest.TestCase):    u‘‘‘測試案例a的集合‘‘‘    @classmethod    def setUpClass(cls):        cls.driver = webdriver.Firefox()    def setUp(self):        self.driver.get("https://www.cnblogs.com/yoyoketang/")    def test_01(self):        u‘‘‘用例1:用例1的操作步驟‘‘‘        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    def test_02(self):        u‘‘‘用例2:用例2的操作步驟‘‘‘        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    def test_03(self):        u‘‘‘用例3:用例3的操作步驟‘‘‘        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    @classmethod    def tearDownClass(cls):        cls.driver.quit()if __name__ == "__main__":    unittest.main()

 

3.run_all代碼

# coding=utf-8import unittestfrom BeautifulReport import BeautifulReportimport osfrom tomorrow import threads# 擷取路徑curpath = os.path.dirname(os.path.realpath(__file__))casepath = os.path.join(curpath, "case")if not os.path.exists(casepath):    print("測試案例需放到‘case’檔案目錄下")    os.mkdir(casepath)reportpath = os.path.join(curpath, "report")if not os.path.exists(reportpath): os.mkdir(reportpath)def add_case(case_path=casepath, rule="test*.py"):    ‘‘‘載入所有的測試案例‘‘‘    discover = unittest.defaultTestLoader.discover(case_path,                                                  pattern=rule,                                                  top_level_dir=None)    return discover@threads(3)def run(test_suit):    result = BeautifulReport(test_suit)    result.report(filename=‘report.html‘, description=‘測試deafult報告‘, log_path=‘report‘)if __name__ == "__main__":    # 用例集合    cases = add_case()    print(cases)    for i in cases:        print(i)        run(i)

 

4.報告

備忘:BeautifulReport是某大神在github分享的架構,這裡借花獻佛了,更多使用方法參考地址:https://github.com/TesterlifeRaymond/BeautifulReport

  

selenium+python自動化91-unittest多線程產生報告(BeautifulReport)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.