Switch to Chrome headless for selenium tests

This commit is contained in:
Johannes Hoppe 2017-07-16 10:03:49 +02:00
parent 78c54f2c47
commit b88e26bfa2
7 changed files with 17 additions and 37 deletions

View file

@ -7,12 +7,9 @@ cache:
services:
- redis
addons:
firefox: latest
apt:
sources:
- google-chrome
chrome: stable
apt:
packages:
- google-chrome-stable
- python3-enchant
- python-enchant
- graphviz
@ -21,10 +18,6 @@ python:
- "3.5"
- "3.6"
env:
global:
- DISPLAY=:99.0
- GECKO_DRIVER_VERSION=v0.16.1
- CHROME_DRIVER_VERSION=2.29
matrix:
- DJANGO=18
- DJANGO=110
@ -50,12 +43,11 @@ matrix:
install:
- pip install --upgrade pip tox
- pip install -U coveralls
- sh -e /etc/init.d/xvfb start
before_script:
- mkdir bin
- export CHROME_DRIVER_VERSION=`curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
- 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
- nvm install --lts
- npm install -g standard

View file

@ -43,7 +43,7 @@ class Select2Conf(AppConf):
"""
CACHE_PREFIX = 'select2_'
"""
If you caching backend doesn't support multiple databases
If you caching backend does not support multiple databases
you can isolate select2 using the cache prefix setting.
It has set `select2_` as a default value, which you can change if needed.
"""

View file

@ -7,7 +7,6 @@ isort
pydocstyle
pytest
pytest-django
pytest-rerunfailures
selenium
sphinx
sphinxcontrib-spelling

View file

@ -24,7 +24,6 @@ pyflakes==1.5.0 # via flake8
pygments==2.2.0 # via sphinx
pytest-django==3.1.2
pytest==3.1.3
pytest-rerunfailures==2.2
pytz==2017.2 # via babel
redis==2.10.5 # via django-redis
selenium==3.4.3

View file

@ -1,21 +1,14 @@
# -*- coding:utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
import random
import string
from time import sleep
import pytest
from django.utils.encoding import force_text
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
browsers = {
'chrome': webdriver.Chrome,
'firefox': webdriver.Firefox,
}
def random_string(n):
return ''.join(
@ -29,22 +22,17 @@ def random_name(n):
return '-'.join([x.capitalize() for x in words])
@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 request.param == 'chrome':
# chrome needs a couple of seconds before it can be quit
sleep(5)
b.quit()

View file

@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
import collections
import json
import os
import pytest
from django.core import signing
@ -341,10 +342,12 @@ class TestHeavySelect2MultipleWidget(object):
form = forms.HeavySelect2MultipleWidgetForm()
widget_cls = HeavySelect2MultipleWidget
@pytest.mark.xfail(bool(os.environ.get('CI', False)),
reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772')
def test_widgets_selected_after_validation_error(self, db, live_server, driver):
driver.get(live_server + self.url)
WebDriverWait(driver, 60).until(
expected_conditions.presence_of_element_located((By.ID, 'it_title'))
WebDriverWait(driver, 3).until(
expected_conditions.presence_of_element_located((By.ID, 'id_title'))
)
title = driver.find_element_by_id('id_title')
title.send_keys('fo')
@ -355,7 +358,7 @@ class TestHeavySelect2MultipleWidget(object):
driver.find_element_by_css_selector('.select2-results li:nth-child(2)').click()
genres.submit()
# there is a ValidationError raised, check for it
errstring = WebDriverWait(driver, 10).until(
errstring = WebDriverWait(driver, 3).until(
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, 'ul.errorlist li'))
).text
assert errstring == "Title must have more than 3 characters."

View file

@ -2,8 +2,8 @@
envlist = py{27,35,36}-dj{18,110,111,master},qa,docs
[testenv]
setenv=
DISPLAY=:99.0
PYTHONPATH = {toxinidir}
passenv=CI
deps=
-rrequirements-dev.txt
dj18: https://github.com/django/django/archive/stable/1.8.x.tar.gz#egg=django
@ -14,7 +14,6 @@ commands=
coverage run --source=django_select2 -m 'pytest' \
--basetemp={envtmpdir} \
--ignore=.tox \
--reruns 3 \
{posargs}
[testenv:qa]