我正在使用Django(1.5.5),selenium(2.41.0),splinter(0.6.0)和phantomjs(1.9.7)来运行实时测试.
虽然测试大多数工作,不时(通常在CircleCI上,在本地VM中较少),但它们会挂起,直到CircleCI上出现超时或手动杀死转子(Ctrl-C即KeyboardInterrupt工作).
这是我的基础测试类的外观:
class SplinterTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
super(SplinterTestCase, cls).setUpClass()
# start phantom just once per class, to speed up tests
cls.phantom = splinter.Browser('phantomjs', load_images=False)
@classmethod
def tearDownClass(cls):
cls.phantom.quit()
super(SplinterTestCase, cls).tearDownClass()
def login(self, *args, **kwargs):
# perform a login using Django builtin "client", steal the session
# cookie and inject it to phantomjs, avoiding the need to do the
# login dance for each test
from django.conf import settings
cn = settings.SESSION_COOKIE_NAME
self.django_client.login(*args, **kwargs)
if cn in self.django_client.cookies:
self.client.driver.add_cookie({
'name': …Run Code Online (Sandbox Code Playgroud)