1 回答

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
我以這種方式解決了問(wèn)題(使用了phantom-js而不是HTMLUNIT,因?yàn)樗俏ㄒ皇S嗟姆€(wěn)定版本的代碼)。
from django.test import LiveServerTestCase
from selenium import webdriver
from os import environ
class SeleniumTestCase(LiveServerTestCase):
__test__ = False
@classmethod
def setUpClass(cls):
environ['NO_PROXY'] = '127.0.0.1' # The key point
cls.selenium = webdriver.PhantomJS(service_args=['--proxy-type=none'])
super(SeleniumTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.close()
cls.selenium.quit()
super(SeleniumTestCase, cls).tearDownClass()
class TestFoo(SeleniumTestCase):
def setUp(self):
# do something before every test method runs
pass
def test_foo(self):
# test
pass
添加回答
舉報(bào)