Django with splinter and phantomjs is painfully slow
Asked Answered
M

1

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.

Matabele answered 23/12, 2013 at 14:25 Comment(0)
R
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.

Revengeful answered 29/1, 2014 at 1:8 Comment(2)
I didn't test this, but it sounds valid to me. Accepting the answer.Matabele
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.Lusty

© 2022 - 2024 — McMap. All rights reserved.