from selenium import webdriver
from HTMLTestRunner import HTMLTestRunner
import unittest
import os
import time
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):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_id("kw").send_keys("unittest")
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()
最近在学习 unittest 框架,照书上的代码,可以运行这个用例,但是在该目录下并没有生成 html 报告文件,求助。