使用的版本是python 3,其中HTMLTestRunner是修改版本,参考以下博客并下载 https://blog.csdn.net/zhanin123/article/details/78950136
import unittest import time import HTMLTestRunner from selenium import webdriver class MyTestCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome('E:\wangjz\testskill\web_auto\chromedriver.exe') #手动指定chrome驱动程序路径 self.driver.implicitly_wait(10) #设置隐式等待时间 self.base_url = 'http://www.baidu.com' def test_search(self): u''' test search ''' driver = self.driver driver.get(self.base_url) #打开网址 driver.find_element_by_id('kw').send_keys(u'钱学森') #定位输入框,输入搜索内容 driver.find_element_by_id('su').click() #定位按钮,并点击 time.sleep(2) def tearDown(self): self.driver.quit() if __name__ == '__main__': with open('report_search.html','wb') as fp: #当前路径下打开一个文件,用于报告写入 runner = HTMLTestRunner.HTMLTestRunner( #使用HTMLTestRunner生成报告 stream=fp, title='report_search', description=u'running case:' ) runner.run(MyTestCase('test_search')) #执行case
运行时选择图1正常生成报告,选择图2则只会运行case,不会生成报告