下面是我在学习中遇到的问题,给大家分享一下:
'''
这里是测试代码
'''
# 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")
# coding = utf-8
from selenium import webdriver
from

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 = "

"
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")

1,先检查
BaiduReport.py 代码,没有检查出问题,错误提示显示第8行 import HTMLTestRunner,检查拼写正确,估计

是引用文件
HTMLTestRunner.py的问题。

2,检查

!)点击蓝色部分,直接打开


查阅资料,StringIO方法是Python里自带的方法,那是哪里出问题了?

难道这个文件出问题了?网上找了帖子,给的链接还是这个链接:
http://tungwaiyip.info/software/HTMLTestRunner.html

去找来一些关于StringIO方法的资料,看到下面的资料时,恍然大悟,考虑应该是Python版本的问题,程序没有错。
后来,找到帖子证明了这个问题,参考:

“import StringIO”改成“from io import StringIO ”,运行成功。
PS:我的Python版本是python 3.6的,import StringIO适用于python 2.X

总结:有些问题,可能找不原因,但是就是报错,这时想一下可能是
1)版本的问题,比如版本发生变化,有的方法不在适用,我们不可能每个版本都去学习,每个版本都去找资料学习,遇到
这类问题要思考是否是版本的问题,自己找资料解决
2)资源释放的问。没有报错,就是没有显示内容,这种问题可能跟资源释放有问题,检查资源是否关闭了。
_____________________________________________________________________________________________
写到这里就结束了,如果有什么疑问可以给我留言哦~