我想为 Django 应用程序编写一些 Selenium 单元测试。我们已经有很多常规的 python 单元测试。我从 Django 文档中复制了示例 selenium 测试(这只不过是 selenium 的“hello world”):
from selenium.webdriver.firefox.webdriver import WebDriver
from django.test import LiveServerTestCase
class MySeleniumTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
super(MySeleniumTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(MySeleniumTestCase, cls).tearDownClass()
def test_simple(self):
self.selenium.get("/")
但是,当我在本地运行此程序或使用CircleCI(测试中的云即服务)时,我收到此错误:
======================================================================
ERROR: test_simple (proj.lib.tests.MySeleniumTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu//proj/proj/lib/tests.py", line 1347, in test_simple
self.selenium.get("/")
File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 185, in get
self.execute(Command.GET, {'url': url})
File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "/home/ubuntu/proj/venv/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'f.QueryInterface is not a function' ; Stacktrace:
at FirefoxDriver.prototype.get (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/driver_component.js:9333)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11455)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11460)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpXXrLF6/extensions/fxdriver@googlecode.com/components/command_processor.js:11402)
这是 Django 1.5.5、python 2.7、selenium python 包 2.42.1
有什么问题?我如何让硒工作?