1

我是 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'
4

1 回答 1

2

和模块已从 Python-3.x 中删除StringIOcStringIO相反,导入io模块并使用io.StringIO. 文档链接

from io import StringIO
于 2015-11-26T12:38:27.693 回答