Commit 9245f6f2 authored by Roman Yurchak's avatar Roman Yurchak

More generic selenium fixture caching mechanism

parent 6b51f3a2
......@@ -103,8 +103,8 @@ class ChromeWrapper(SeleniumWrapper):
if pytest is not None:
@pytest.fixture(params=['firefox', 'chrome'], scope='module')
def selenium(request):
@pytest.fixture(params=['firefox', 'chrome'])
def selenium_standalone(request):
if request.param == 'firefox':
cls = FirefoxWrapper
elif request.param == 'chrome':
......@@ -116,6 +116,30 @@ if pytest is not None:
print('\n'.join(str(x) for x in selenium.logs))
selenium.driver.quit()
@pytest.fixture(params=['firefox', 'chrome'], scope='module')
def _selenium_cached(request):
# intermediary cached selenium instance, this is a copy
# of the selenium_standalone to avoid fixture scope issues
if request.param == 'firefox':
cls = FirefoxWrapper
elif request.param == 'chrome':
cls = ChromeWrapper
selenium = cls()
try:
yield selenium
finally:
selenium.driver.quit()
@pytest.fixture
def selenium(_selenium_cached):
# this is selenium instance cached at the module level
try:
# for each test run, we clean selenium logs
_selenium_cached.driver.execute_script("window.logs = []")
yield _selenium_cached
finally:
print('\n'.join(str(x) for x in _selenium_cached.logs))
PORT = 0
......
......@@ -32,16 +32,17 @@ UNSUPPORTED_PACKAGES = {'ChromeWrapper': ['pandas'],
@pytest.mark.parametrize('name', registered_packages())
def test_import(name, selenium):
def test_import(name, selenium_standalone):
# check that we can parse the meta.yaml
meta = common.parse_package(PKG_DIR / name / 'meta.yaml')
if name in UNSUPPORTED_PACKAGES[selenium.__class__.__name__]:
if name in UNSUPPORTED_PACKAGES[selenium_standalone.__class__.__name__]:
pytest.xfail(
'{} fails to load and is not supported on {}.'
.format(name,
selenium.__class__.__name__.replace('Wrapper', '')))
'{} fails to load and is not supported on {}.'
.format(name,
selenium_standalone.__class__.__name__
.replace('Wrapper', '')))
for import_name in meta.get('test', {}).get('imports', []):
selenium.load_package(name)
selenium.run('import %s' % import_name)
selenium_standalone.load_package(name)
selenium_standalone.run('import %s' % import_name)
......@@ -6,9 +6,9 @@ import time
import pytest
def test_init(selenium):
assert 'Python initialization complete' in selenium.logs
assert len(selenium.driver.window_handles) == 1
def test_init(selenium_standalone):
assert 'Python initialization complete' in selenium_standalone.logs
assert len(selenium_standalone.driver.window_handles) == 1
def test_webbrowser(selenium):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment