(Forty-seven) HTML test application of advanced automated test report - test report more readable

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

More readable test report

Now the generated test report is not legible, because it listed a bunch of test class and test methods, we need to carefully named in order to improve the readability of the test report as a test class and test methods. If any name is " test_case1 ", " test_case2, " and so on, then the report will lose its readability, perhaps a long time even script developers are not clear " test_case1 " What is the function of the test.

When writing functional test cases, each test case has a title, then we can also add the title of it is automated test cases? Before that let's learn another knowledge: Python comments. Python Notes, there are two, called conment , another called DOC String , as the former general comment, which is used to describe functions, classes, and methods.

 

 

 

Below class or method, by three quotation marks ( '' '' '' or "" "" "" ) to add doc string type of annotation, such annotations call when not in the usual display, by () Help method View this annotated classes or methods.

 

Back to the question of the far point, HTMLTestRunner can read the doc string type of comment. So, we need to test class or method to add this type of comment.

 

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):
        '''搜索关键字:HTMLTestRunner'''
        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,"百度一下,你就知道")

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

if the __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 = ' with Example implementation: ' ) 
    runner.run (TestUnit)# Run the test cases 
    fp.close () # close the report file

 

Re-run the test case to see test report:

Guess you like

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