【问题标题】:Setting a test using xvfb + PyCharm + vagrant使用 xvfb + PyCharm + vagrant 设置测试
【发布时间】:2015-06-03 06:51:04
【问题描述】:
我有这个环境:
- 在 Mac OS X 上运行的 PyCharm
- 在 vagrant 实例中运行在 Ubuntu Server 上的 Python3.4 环境
我希望能够使用 PyCharm 运行/调试测试。到目前为止,我可以做到,但我最近在我的测试中添加了 selenium,现在我需要将 python 解释器包装在 xvfb-run 远程命令中。我尝试添加一个远程外部工具,但我还不能让它工作。我找到了this guy,但他并没有很好地解释他是如何做到的。任何想法将不胜感激:-)
【问题讨论】:
标签:
python
selenium
pycharm
xvfb
【解决方案1】:
感谢this answer,我没有添加外部工具就解决了。步骤:
- 在远程 python 环境中安装了 xvfbwrapper
-
代码示例:
from selenium.webdriver.firefox.webdriver import WebDriver
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from xvfbwrapper import Xvfb
class UITestCase(StaticLiveServerTestCase):
fixtures = ['data.json']
@classmethod
def setUpClass(cls):
cls.vdisplay = Xvfb()
cls.vdisplay.start()
cls.selenium = WebDriver()
cls.selenium.implicitly_wait(3000)
super(UITestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
cls.vdisplay.stop()
super(UITestCase, cls).tearDownClass()
def test_list(self):
self.selenium.get('%s%s' % (self.live_server_url, '/#/app'))
count = len(self.selenium.find_elements_by_xpath('//*[@id="data"]/tbody/tr'))
self.assertEqual(count, 2)
- 无需更改您的测试配置(假设它已经成功运行)