1.下载htmltestrunner
http://tungwaiyip.info/software/HTMLTestRunner.html
2.下载文件放在Python安装路径下lib文件夹
3.demo
from selenium import webdriver
import unittest
from HTMLTestRunner import HTMLTestRunner
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
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").send_keys("HTMLTestRunner")
driver.find_element_by_id("su").click()
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_baidu_search"))
# 定义报告存放路径
fp = open('./result.html', "wb")
# 定义测试报告
runner = HTMLTestRunner(stream=fp,
title='百度搜索测试报告',
description='用例执行情况:')
runner.run(testunit)
fp.close()