Django与splinter和phantomjs是痛苦的慢 [英] Django with splinter and phantomjs is painfully slow

查看:270
本文介绍了Django与splinter和phantomjs是痛苦的慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我尝试将django的 LiveServerTestCase splinter phantomjs webdriver。

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)

有时测试运行正常 - 即使每次测试需要一秒执行方法但是有时可以随意花费大约100秒钟来执行单一的测试方法,否则它会冻结,直到我忍耐等待完成。

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.

我使用 django_nose 作为测试运行器,我通过 - liveserver = localhost:8081-8181 端口范围为 ./ manage.py test 命令。

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

有没有办法加速?有没有其他web测试运行器可以哪个更快?

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

默认网络驱动程序似乎更加可靠,速度(每个测试方法1-3秒),但它是还是很慢我也更喜欢一个无头浏览器进行测试。

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.

推荐答案

什么让测试缓慢打开并关闭每个测试的浏览器。改进测试时间的方法是打开浏览器一次。你可以使用setUpClass和tearDownClass来实现。

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.

这篇关于Django与splinter和phantomjs是痛苦的慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆