From e38ea1ffd1eef4c2944b8aa22a0a71319606839a Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Tue, 10 Dec 2019 23:06:13 +0100 Subject: [PATCH] [CI] Introduce Selenium tests against Docker --- .gitlab-ci.yml | 15 +++++++++++---- biscuit/core/tests/browser/test_selenium.py | 17 +++++++++++++++++ tox.ini | 11 +++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 biscuit/core/tests/browser/test_selenium.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc0e6c70b..b40a30f60 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,19 +62,26 @@ build_docker: --cache=true --cleanup -test_docker: +test_docker_selenium: stage: test_integrated image: - name: debian:buster-slim + name: registry.edugit.org/teckids/docker-images/python-pimped:master services: - name: postgres:12 alias: db - - name: memcached:latest + - name: memcached alias: memcached - name: registry.edugit.org/biscuit/biscuit-ng:${CI_COMMIT_REF_NAME} alias: app + before_script: + - apt-get -y update && eatmydata apt-get -y install chromium-driver + - eatmydata pip install selenium pytest-selenium + - adduser --disabled-password --gecos "Test User" testuser script: - - echo true + - sudo -u testuser eatmydata tox -e selenium + artifacts: + paths: + - screenshots/ deploy_demo-master: stage: deploy diff --git a/biscuit/core/tests/browser/test_selenium.py b/biscuit/core/tests/browser/test_selenium.py new file mode 100644 index 000000000..1a665ae3f --- /dev/null +++ b/biscuit/core/tests/browser/test_selenium.py @@ -0,0 +1,17 @@ +import sys + +import pytest + +if '--driver' not in sys.argv: + pytest.skip('Selenium driver not configured', allow_module_level=True) + +@pytest.fixture +def chrome_options(chrome_options): + chrome_options.add_argument('--headless') + chrome_options.add_argument('--no-sandbox') + chrome_options.add_argument('--disable-dev-shm-usage') + return chrome_options + +def test_index(selenium): + selenium.get('http://app:8000/') + selenium.save_screenshot('screenshots/index.png') diff --git a/tox.ini b/tox.ini index defacd8dd..59ea1468c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,18 @@ [tox] skipsdist = True +envlist = default -[testenv] +[testenv:default] whitelist_externals = poetry pytest skip_install = true -commands = pytest --pylama --cov=biscuit biscuit/core/ +commands = pytest -p no:selenium --pylama --cov=biscuit biscuit/core/ + +[testenv:selenium] +whitelist_externals = poetry + pytest +skip_install = true +commands = pytest --driver {env:SELENIUM_DRIVER:Chrome} biscuit/core/ [pylama] linters = pycodestyle,pyflakes,radon -- GitLab