from selenium import webdriver
import unittest,time
from HTMLTestRunner import HTMLTestRunner
class MyTest(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(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_id('kw').send_keys('测试')
driver.find_element_by_id('su').click()
print(driver.title)
self.assertEqual(driver.title, "百度一下,你就知道")
def tearDown(self):
self.driver.quit()
if name == ‘main’:
# unittest.main()
# 构建测试集
testsuite = unittest.TestSuite()
testsuite.addTest(MyTest('test_baidu'))
# 定义报告存放路径
# fp = open('./result.html','wb')
now = time.strftime("%Y-%m-%d %H-%M-%S")
filename = './' + now + "result.html"
fp = open(filename, "wb")
# 定义测试报告
runner = HTMLTestRunner(stream=fp,title = '百度搜索测试报告',description = '用例执行情况:')
# 运行测试用例
runner.run(testsuite)
# 关闭报告文件
fp.close()