3

Today I tried combining django's LiveServerTestCase with splinter and phantomjs webdriver.

Here's what I do (simplified version):

class Test(LiveServerTestCase):

    def setUp(self):
        self.browser = Browser('phantomjs')

    def tearDown(self):
        self.browser.quit()

    def test(self):
        self.browser.visit(self.live_server_url)
        self.assertIn("Hello world!", self.browser.title)

Sometimes tests run fine - even though taking a second per test method to execute. But sometimes it can randomly take ~100 seconds for that single test method to execute, or it just freezes until I am out of patience to wait for it to finish.

I use django_nose as a test runner, and I pass --liveserver=localhost:8081-8181 range of ports to ./manage.py test command.

Is there any way to speed it up? Is there other web test runner I can which is faster?

Default web driver seem to be more reliable speed-wise (1-3 seconds per test method), but it's still pretty slow. I also would prefer a headless browser for testing.

Ruslan Osipov
  • 5,655
  • 4
  • 29
  • 44

1 Answers1

6

What makes the tests slow is open and close the browser on each test. A way to improve the tests time is open the browser once. You can do it using setUpClass and tearDownClass.

  • I didn't test this, but it sounds valid to me. Accepting the answer. – Ruslan Osipov Jan 29 '14 at 05:04
  • 1
    This is actually probably NOT the issue. The question asks about tests taking longer than 100 seconds to complete. The issue is much more likely to do with the fact that the LiveTestServer only has a single thread, and if it gets held up, nothing can proceed. – mlissner Apr 05 '16 at 22:11