为此我使用它通过指定的网络驱动器运行测试简单的装饰:
import functools
def run_through_drivers(driver_pool='drivers'):
def wrapped(test_func):
@functools.wraps(test_func)
def decorated(test_case, *args, **kwargs):
test_class = test_case.__class__
web_driver_pool = getattr(test_class, driver_pool)
for web_driver in web_driver_pool:
setattr(test_case, 'selenium', web_driver)
test_func(test_case, *args, **kwargs)
return decorated
return wrapped
如何使用方法:
class UITest(LiveServerTestCase):
fixtures = ['initial_test_data.json']
selenium = None
@classmethod
def setUpClass(self):
cls.drivers = WebDriverList(
webdriver.Chrome(),
webdriver.Firefox(),
webdriver.PhantomJS
)
super(UITest, cls).setUpClass()
@classmethod
def tearDownClass(cls):
for driver in cls.drivers:
driver.quit()
super(UITest, cls).tearDownClass()
@run_through_drivers()
def test_example(self):
...
来自Evan Lewis的更完整的[解决方案](https://groups.google.com/d/msg/django-users/Sckf9y2xIho/mwLTr8YyNDkJ)。 – 2014-11-08 20:42:10
真棒,谢谢! – aphex 2014-11-08 21:56:58