diff --git a/biscuit/core/tests/browser/test_selenium.py b/biscuit/core/tests/browser/test_selenium.py index 96f8f8bbf8f4b825f6fd78242f2ad817348e34ca..6b352c56d74548fc49fc99488f492d3a2d3c6cc3 100644 --- a/biscuit/core/tests/browser/test_selenium.py +++ b/biscuit/core/tests/browser/test_selenium.py @@ -2,31 +2,24 @@ import os import pytest -from django.test import LiveServerTestCase +from django.test.selenium import SeleniumTestCase -webdriver = pytest.importorskip('selenium.webdriver') +if not os.environ.get('TEST_SELENIUM_HUB', None): + pytest.skip('Selenium hub not defined.', allow_module_level=True) -class SeleniumTests(LiveServerTestCase): - __test__ = False - @classmethod - def setUpClass(cls): - super().setUpClass() - - cls.selenium.set_window_size(1920, 1080) - cls.selenium.implicitly_wait(10) - - @classmethod - def tearDownClass(cls): - cls.selenium.quit() - super().tearDownClass() +class SeleniumTests(SeleniumTestCase): + external_host = os.environ.get('TEST_LISTEN_ADDRESS', '127.0.0.1') + browsers = ['chrome', 'firefox'] + selenium_hub = 'http://%s/wd/hub' % os.environ.get('TEST_SELENIUM_HUB', '127.0.0.1:4444') @classmethod def _screenshot(cls, filename): screenshot_path = os.environ.get('TEST_SCREENSHOT_PATH', None) if screenshot_path: - return cls.selenium.save_screenshot(os.path.join(screenshot_path, filename)) + os.makedirs(os.path.join(screenshot_path, cls.browser), exist_ok=True) + return cls.selenium.save_screenshot(os.path.join(screenshot_path, cls.browser, filename)) else: return False @@ -35,31 +28,3 @@ class SeleniumTests(LiveServerTestCase): self.selenium.get(self.live_server_url + '/') assert 'BiscuIT' in self.selenium.title self._screenshot('index.png') - - -class SeleniumTestsChromium(SeleniumTests): - __test__ = True - - @classmethod - def setUpClass(cls): - options = webdriver.ChromeOptions() - options.add_argument('--headless') - options.add_argument('--no-headless') - options.add_argument('--disable-dev-shm-usage') - options.add_argument('--disable-extensions') - options.add_argument('--disable-gpu') - options.add_argument("--disable-impl-side-painting") - options.add_argument("--disable-setuid-sandbox") - options.add_argument("--disable-seccomp-filter-sandbox") - options.add_argument("--disable-breakpad") - options.add_argument("--disable-client-side-phishing-detection") - options.add_argument("--disable-cast") - options.add_argument("--disable-cast-streaming-hw-encoding") - options.add_argument("--disable-cloud-import") - options.add_argument("--disable-popup-blocking") - options.add_argument("--ignore-certificate-errors") - options.add_argument("--disable-session-crashed-bubble") - - cls.selenium = webdriver.Chrome(options=options) - - super().setUpClass() diff --git a/tox.ini b/tox.ini index 26957ad8cb01c3445ce08501e51726011be98c79..3a10d7fabc5859e27c93116ad684dded79a1b5f7 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,8 @@ skip_install = true commands = pytest --pylama --cov=biscuit biscuit/core/ setenv = TEST_SCREENSHOT_PATH = {env:TEST_SCREENSHOT_PATH:} + TEST_SELENIUM_HUB = {env:TEST_SELENIUM_HUB:} + TEST_LISTEN_ADDRESS = {env:TEST_LISTEN_ADDRESS:127.0.0.1} [pylama] linters = pycodestyle,pyflakes,radon