(Forty-six) HTML test report advanced applications of automated test - generate HTML test report

Essays and records to facilitate their access to fellow travelers.

#------------------------------------------------I ------------------------------------------- dividing line is a shame

  Learning before selenium automation, it is best to learn HTML, CSS, JavaScript and other knowledge, help to understand the principles of operation and positioning elements. About python and selenium install any additional information please search on their own here do not introduced, all examples are performed using python3.6 + selenium.

#------------------------------------------------I ------------------------------------------- dividing line is a shame

Generate HTML test report

# !/usr/bin/env python
# -*- coding: UTF-8 –*-
__author__ = 'Mr.Li'

from selenium import webdriver
import unittest
from HTMLTestRunner import HTMLTestRunner

class Baidu(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.base_url = 'http://www.baidu.com'

    def test_baidu_search(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id('kw').clear()
        driver.find_element_by_id('kw').send_keys('HTMLTestRunner')
        driver.find_element_by_id('su').click()
        title = driver.title
        self.assertEqual (title, " Baidu, you know ." )

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    testunit = unittest.TestSuite()
    testunit.addTest (Baidu ( ' test_baidu_search ' ))

    # Storage path defined report 
    FP = Open ( ' ./result.html ' , ' WB ' )
     # define test report 
    Runner = HTMLTestRunner (Stream = FP,
                            title = ' Baidu search test report ' ,
                            Description = ' implementation use cases: ' )
    runner.run (TestUnit) # run a test case 
    fp.close () # close the report file

Code Analysis

First, the HTMLTestRunner module import introduced in.

Secondly, the open () method to open in the current directory in binary write mode result.html , if not, the file is automatically created.

Next, call HTMLTestRunner the module HTMLTestRunner class. stream designated test report file, title to define the title of the test report, the Description for the subtitle-defined test reports.

Finally, HTMLTestRunner of () RUN method to run the test suite assembled test. Finally ) close ( close the file test report.

Use cases run is complete, open the current directory under " result.html " file to view the generated test report, as follows:

 

Guess you like

Origin www.cnblogs.com/lirongyang/p/11595696.html