Reputation: 2452
I have this environment:
I want to be able to run/debug tests using PyCharm. So far I can do it but I recently added selenium to my tests now I need to wrap the python interpreter within xvfb-run remote command. I tried adding a remote external tool but I can't make it work yet. I found this guy but he doesn't explain very well how he made it. Any idea would be very appreciated :-)
Upvotes: 1
Views: 1483
Reputation: 2452
Thanks to this answer, I solved without adding an external tool. Steps:
Code sample:
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)
Upvotes: 3