import unittest
from selenium import webdriverimport HTMLTestRunnerclass Test(unittest.unitcase):
def setUpClass(self): pass def tearDownClass(self): pass def setUp(self): self.driver=webdriver.chrome() def tearDown(self): slef.deiver.quit() #获取标题 def test_getTitle(self): url='http://www.baidu.com' self.driver.get(url) title=self.driver.title print(' 当前网页的titlt为:',title) self.assertEqual(title,'百度一下,你就知道;,'页面TITLE错误')if __init__=='__name__':
unittest.main()#或者if __init__=='__main__': suite=unittest.suite() suite.addTests(unittest.TestLoad().loadTestSFromTestCase(TestClass) with open(filename,'wb') as fp: runner=HTMLTestRunner(stream=fp,title='标题', description='测试用例') runner.run(suite)