1. 程式人生 > >python+unittest 生成HTML報告

python+unittest 生成HTML報告

from selenium import webdriver
import unittest
import time
import HTMLTestrunner
class BaiDu(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Chrome()
        self.driver.get("http://www.baidu.com")
        self.driver.implicitly_wait(3)
        self.driver.maximize_window()

    def test_case(self):
        time.sleep(2)
        self.driver.find_element_by_id("kw").send_keys("selenium")
        self.driver.find_element_by_id("su").click()
    def tearDown(self):
        self.driver.quit()

if  __name__=="__main__":
    filepath = 'C:\\Intel\\htmlreport.html'
    ftp = open(filepath, 'wb')
    suite = unittest.TestSuite()
    suite.addTest(BaiDu('test_case'))
    runner = HTMLTestrunner.HTMLTestRunner(stream=ftp, title='welcome to this web')
    runner.run(suite)
    unittest.main()