From 02e70d59628e25ba20e34028df2e9edabf3600af Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Wed, 11 Dec 2019 12:09:25 +0100 Subject: [PATCH] [Tests] Use SeleniumTestCase --- biscuit/core/tests/browser/test_selenium.py | 53 ++++----------------- tox.ini | 2 + 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/biscuit/core/tests/browser/test_selenium.py b/biscuit/core/tests/browser/test_selenium.py index 96f8f8bbf..6b352c56d 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 26957ad8c..3a10d7fab 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 -- GitLab