我是selenium + python的新手。
当我包含htmltestrunner来生成报告时,我遇到了问题。我使用的是Python3.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.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 1
06, in exec_file
exec_code(code, file, global_variables)
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 8
2, in exec_code
exec(code_obj, global_variables)
File "c:\users\documents\visual studio 2013\Projects\TestOfR
eport\TestOfReport\TestOfReport.py", line 10, in <module>
import HTMLTestRunner
File "C:\Python34\lib\site-packages\HTMLTestRunner.py", line 94, in <module>
import StringIO
ImportError: No module named 'StringIO'
答案 0 :(得分:0)
已从Python-3.x中删除StringIO
和cStringIO
模块。而是导入io
模块并使用io.StringIO
。 Doc link
from io import StringIO