From 4114b097e2348edd503435007fe4ba6165cc81bb Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Thu, 17 Aug 2017 23:09:48 +0200 Subject: [PATCH] Switch to Chrome headless for Selenium test --- .travis.yml | 3 --- tests/conftest.py | 18 ++++++------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88937a6..5abde3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ python: - '3.6' env: global: - - DISPLAY=:99.0 - GECKO_DRIVER_VERSION=v0.16.1 - CHROME_DRIVER_VERSION=2.29 matrix: @@ -42,12 +41,10 @@ matrix: install: - pip install --upgrade pip tox - pip install -U coveralls -- sh -e /etc/init.d/xvfb start before_script: - mkdir bin - curl -O https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip - unzip chromedriver_linux64.zip -d bin -- curl -Lo - "https://github.com/mozilla/geckodriver/releases/download/${GECKO_DRIVER_VERSION}/geckodriver-${GECKO_DRIVER_VERSION}-linux64.tar.gz" | tar xzf - -C bin - PATH=$PATH:$PWD/bin - | if [[ -z $TOXENV ]]; then diff --git a/tests/conftest.py b/tests/conftest.py index 894810d..f6406ad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,6 @@ import os import tempfile -from time import sleep import pytest from django.core.files.base import ContentFile @@ -17,22 +16,17 @@ } -@pytest.yield_fixture(scope='session', params=sorted(browsers.keys())) -def driver(request): - if 'DISPLAY' not in os.environ: - pytest.skip('Test requires display server (export DISPLAY)') - +@pytest.yield_fixture(scope='session') +def driver(): + chrome_options = webdriver.ChromeOptions() + chrome_options.add_argument('headless') + chrome_options.add_argument('window-size=1200x800') try: - b = browsers[request.param]() + b = webdriver.Chrome(chrome_options=chrome_options) except WebDriverException as e: pytest.skip(force_text(e)) else: - b.set_window_size(1200, 800) - b.implicitly_wait(0.1) yield b - if isinstance(b, webdriver.Chrome): - # chrome needs a couple of seconds before it can be quit - sleep(5) b.quit()