我是硒+python的新手。
当我包含htmltestrunner来生成报告时,我遇到了一个问题。我使用的是Python 3.4。
下面是我的代码,如果我正在做一些不同于我应该做的事情,请告诉我。
class TestOfReport(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Firefox()
self.base_url="https://www.google.co.in/"
self.driver.implicitly_wait(30)
self.verificationErrors = []
self.accept_next_alert = True
def test_TestOfReport(self):
driver=self.driver
driver.get(self.base_url)
driver.maximize_window()
driver.find_element_by_id("sb_ifc0").send_keys("selenium webdriver")
driver.find_element_by_name("btnK").click()
self.assertIn("Google",driver.title)
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
HTMLTestRunner.main()
错误:
Traceback (most recent call last):
File "C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDEExtensio
nsMicrosoftPython Tools for Visual Studio2.1visualstudio_py_util.py", line 1
06, in exec_file
exec_code(code, file, global_variables)
File "C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDEExtensio
nsMicrosoftPython Tools for Visual Studio2.1visualstudio_py_util.py", line 8
2, in exec_code
exec(code_obj, global_variables)
File "c:usersdocumentsvisual studio 2013ProjectsTestOfR
eportTestOfReportTestOfReport.py", line 10, in <module>
import HTMLTestRunner
File "C:Python34libsite-packagesHTMLTestRunner.py", line 94, in <module>
import StringIO
ImportError: No module named 'StringIO'
StringIO
和cStringIO
模块已从Python-3.x中删除。请导入io
模块并使用io.StringIO
。文档链接。
from io import StringIO