通常的設置是在類的拆卸方法中退出PhantomJS瀏覽器。例如:
from django.conf import settings
from django.test import LiveServerTestCase
from selenium.webdriver.phantomjs.webdriver import WebDriver
PHANTOMJS = (settings.BASE_DIR +
'/node_modules/phantomjs/bin/phantomjs')
class PhantomJSTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.web = WebDriver(PHANTOMJS)
cls.web.set_window_size(1280, 1024)
super(PhantomJSTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
screenshot_file = getattr(settings, 'E2E_SCREENSHOT_FILE', None)
if screenshot_file:
cls.web.get_screenshot_as_file(screenshot_file)
cls.web.quit()
super(PhantomJSTestCase, cls).tearDownClass()
如果不使用unittest
測試情況下,你必須自己使用quit
方法。您可以使用atexit
模塊在Python進程終止時運行代碼,例如:
import atexit
web = WebDriver(PHANTOMJS)
atexit.register(web.quit)
沒有幫助,我通常終止調試過程以節省時間。我可以停止這樣做,但我真的很喜歡它,所以如果有解決方案,我很樂意。 (當我修復代碼時終止更好,因爲沒有必要繼續運行舊版本的代碼。) – 2014-08-30 22:31:59
這兩個選項都應該在那裏工作。你如何終止python過程? – 2014-08-31 07:22:45
我的調試器有一個終止進程的快捷方式(Ctrl-F5,並不重要)。它只是立即停止進程。在這些情況下,據我所知,任何'tearDown'方法或'atexit'處理程序都不會被調用。 – 2014-08-31 10:04:24