# coding = utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import HTMLTestRunner
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com
"
self.verificationErrors = []
self.accept_next_alert = True
#测试用例
def test_baidu_search(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(2)
driver.close()
def tearDown(self):
self.driver.quit()
self.assertEquals([], self.verificationErrors)
if __name__ == "__main__":
#定义一个单元测试容器
testunit = unittest.TestSuite()
#将测试用例加入到测试容器中
testunit.addTest(Baidu("test_baidu_search"))
#定义个报告存放路径,支持相对路径
filename = "E:\\result.html"
fp = file(filename, "wb")
查阅资料,StringIO方法是Python里自带的方法,那是哪里出问题了?HTMLTestRunner.py是自从网上下载别人写好的文件,
后来,找到帖子证明了这个问题,参考:https://blog.csdn.net/wodedipang_/article/details/80062160
总结:有些问题,可能找不原因,但是就是报错,这时想一下可能是