foreword
The selenium multi-threaded running use case has been solved in the previous article. How to generate a test report is a difficult point. There is just a great god on github who shared BeautifulReport, which can be combined perfectly to generate a report.
Environment must:
- python3.6 : BeautifulReport does not support 2.7
- tomorrow : pip install tomorrow安装
- BeautifulReport : After downloading from github, put it in the /Lib/site-packages/ directory
BeautifulReport
1.BeautifulReport download address: BeautifulReport
2. Download method:
- Method one will use git to download directly to the local with git
git clone https://github.com/TesterlifeRaymond/BeautifulReport
- The second method is to click the Clone or Download button, and the Download ZIP can be downloaded locally.
3. After downloading, put the entire BeautifulReport package in the /Lib/site-packages/ directory of python
Instructions
1. Project structure:
The .py use case script
report at the beginning of case test puts the generated html report
run_all.py for executing all scripts
2. A single test script test_a.py reference
# coding:utf-8 import unittest from selenium import webdriver import time class Test (unittest.TestCase): u ''' A collection of test cases ''' @classmethod def setUpClass(cls): cls.driver = webdriver.Firefox() def setUp(self): self.driver.get("https://www.cnblogs.com/yoyoketang/") def test_01(self): u ''' Use case 1: Operation steps of use case 1 ''' t = self.driver.title print (t) self.assertIn( " yoyo " , t) def test_02(self): u ''' Use case 2: Operation steps of use case 2 ''' t = self.driver.title print (t) self.assertIn( " yoyo " , t) def test_03(self): u ''' Use case 3: Operation steps of use case 3 ''' t = self.driver.title print (t) self.assertIn( " yoyo " , t) @classmethod def tearDownClass(cls): cls.driver.quit() if __name__ == "__main__": unittest.main()
3.run_all code
# coding=utf-8 import unittest from BeautifulReport import BeautifulReport import os from tomorrow import threads #Get the path curpath = os.path.dirname(os.path.realpath( __file__ )) casepath = os.path.join(curpath, " case " ) if not os.path.exists(casepath): print ( "The test case needs to be placed in the 'case' file directory " ) 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 " ): ''' Load all test cases ''' 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= ' test deafult report ' , log_path= ' report ' ) if __name__ == " __main__ " : #use case collection cases = add_case() print(cases) for i in cases: print(i) run(i)
4. Report renderings
Remarks: BeautifulReport is a framework shared by a great god on github. Here, I borrow flowers to offer Buddha. For more usage, please refer to the address: https://github.com/TesterlifeRaymond/BeautifulReport