Skip to content

Commit ee2cbdf

Browse files
authored
Use chrome and firefox in headless mode (#221)
* Use chrome and firefox in headless mode * Fix geckodriver script to be more linux friendly * Docs and final travis.yml touches
1 parent a26c408 commit ee2cbdf

File tree

7 files changed

+115
-25
lines changed

7 files changed

+115
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__
55
.idea
66
.pytest_cache
77
.tox
8+
.vscode/
89
*.egg-info/
910
*.pyc
1011
build

.travis.yml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
language: python
22
jobs:
33
include:
4-
- stage:
4+
- stage: Linting
55
python: 3.7
66
dist: xenial
77
sudo: required
8+
before_install: skip
9+
addons: skip
810
env: TOXENV=flake8
911

10-
- stage:
12+
- stage: Docs
1113
python: 3.7
1214
dist: xenial
1315
sudo: required
16+
before_install: skip
17+
addons: skip
1418
env: TOXENV=docs
1519

16-
- stage:
20+
- stage: python 2.7
1721
python: 2.7
1822
env: TOXENV=py27
19-
services:
20-
- xvfb
2123

22-
- stage:
24+
- stage: python 3.6
2325
python: 3.6
2426
env: TOXENV=py36
25-
services:
26-
- xvfb
2727

28-
- stage:
28+
- stage: python 3.7
2929
python: 3.7
3030
dist: xenial
3131
sudo: required
3232
env: TOXENV=py37
33-
services:
34-
- xvfb
3533

36-
- stage:
34+
- stage: pypy 5.6.0
3735
python: pypy-5.6.0
3836
env: TOXENV=pypy
39-
services:
40-
- xvfb
4137

4238
- stage: deploy
4339
python: 3.7
@@ -46,6 +42,7 @@ jobs:
4642
before_install: skip
4743
install: skip
4844
script: skip
45+
addons: skip
4946
deploy:
5047
provider: pypi
5148
user: davehunt
@@ -60,21 +57,21 @@ sudo: required
6057

6158
env:
6259
global:
63-
- DISPLAY=:99.0
64-
- GECKODRIVER_VERSION=0.21.0
65-
- PYTEST_ADDOPTS="-m 'not (chrome or edge or safari or phantomjs)'"
60+
- PYTEST_ADDOPTS="-m 'not (edge or safari or phantomjs)'"
61+
- GECKODRIVER_FALLBACK_VERSION="v0.24.0"
6662

6763
cache: pip
6864

6965
before_install:
70-
- curl -L -o /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER_VERSION/geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz
71-
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
72-
- export PATH=$HOME/geckodriver:$PATH
73-
- geckodriver --version
66+
- sudo apt-get update
67+
- sudo apt-get install -y curl jq
68+
- sudo installation/geckodriver.sh latest
69+
- sudo installation/chromedriver.sh latest
7470

7571
install: pip install tox
7672

7773
script: tox
7874

7975
addons:
8076
firefox: latest
77+
chrome: stable

docs/development.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,39 @@ against the supported Python versions.
2424
2525
$ pip install tox
2626
$ tox
27+
28+
Drivers
29+
-------
30+
To run the tests you'll going to need some browser drivers.
31+
32+
Chromedriver
33+
~~~~~~~~~~~~
34+
To install the latest `chromedriver <https://sites.google.com/a/chromium.org/chromedriver/>`_
35+
on your Mac or Linux (64-bit), run:
36+
37+
.. code-block:: bash
38+
39+
$ ./installation/chromedriver.sh
40+
41+
For Windows users, please see `here <https://sites.google.com/a/chromium.org/chromedriver/getting-started>`_.
42+
43+
Geckodriver
44+
~~~~~~~~~~~
45+
To install the latest `geckodriver <https://firefox-source-docs.mozilla.org/testing/geckodriver/>`_
46+
on your Mac or Linux (64-bit), run:
47+
48+
.. code-block:: bash
49+
50+
$ ./installation/geckodriver.sh
51+
52+
Safaridriver
53+
~~~~~~~~~~~~
54+
Instructions for `safaridriver <https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?language=objc>`_.
55+
56+
Edgedriver
57+
~~~~~~~~~~
58+
Instructions for `edgedriver <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads>`_.
59+
60+
IEDriver
61+
~~~~~~~~
62+
Instructions for `iedriver <https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver>`_.

installation/chromedriver.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
version=${1:-latest}
6+
7+
install_dir="/usr/local/bin"
8+
drivername="chromedriver"
9+
base_url="https://${drivername}.storage.googleapis.com"
10+
11+
[[ ${version} == "latest" ]] && version=$(curl -s "${base_url}/LATEST_RELEASE")
12+
13+
[[ $(uname) == "Darwin" ]] && os="mac" || os="linux"
14+
15+
filename="${drivername}_${os}64.zip"
16+
curl -sL -o /tmp/"${filename}" "${base_url}/${version}/${filename}"
17+
unzip -q /tmp/"${filename}"
18+
mv ${drivername} "${install_dir}"
19+
20+
[[ $(uname) == "Linux" ]] && chmod +x "${install_dir}/${drivername}"
21+
22+
echo "${drivername} ${version} is now available in '${install_dir}'"

installation/geckodriver.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
version=${1:-latest}
6+
7+
install_dir="/usr/local/bin"
8+
base_url="https://github.com/mozilla/geckodriver/releases/download"
9+
10+
if [[ ${version} == "latest" ]]; then
11+
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
12+
version=$(echo "${json}" | jq -r '.tag_name')
13+
# In case of "API rate limit exceeded"
14+
# See https://developer.github.com/v3/#rate-limiting
15+
[[ ${version} == "null" ]] && version=${GECKODRIVER_FALLBACK_VERSION}
16+
else
17+
version="v${version}"
18+
fi
19+
20+
[[ $(uname) == "Darwin" ]] && os="macos" || os="linux64"
21+
22+
filename="geckodriver-${version}-${os}.tar.gz"
23+
curl -sL -o /tmp/"${filename}" "${base_url}/${version}/${filename}"
24+
tar -xf /tmp/"${filename}" -C "${install_dir}"
25+
rm /tmp/"${filename}"
26+
echo "geckodriver ${version} is now available in '${install_dir}'"

testing/conftest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@ def testdir(request, httpserver_base_url):
2626

2727
testdir = request.getfixturevalue("testdir")
2828

29-
testdir.makepyfile(
30-
conftest="""
29+
conftest = """
3130
import pytest
3231
@pytest.fixture
3332
def webtext(base_url, selenium):
3433
selenium.get(base_url)
3534
return selenium.find_element_by_tag_name('h1').text
3635
"""
37-
)
36+
37+
if item.get_closest_marker("chrome"):
38+
conftest += """
39+
@pytest.fixture
40+
def chrome_options(chrome_options):
41+
chrome_options.add_argument("headless")
42+
return chrome_options
43+
"""
44+
45+
testdir.makepyfile(conftest=conftest)
3846

3947
testdir.makefile(
4048
".cfg",

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
envlist = py{27,36,37,py,py3}, docs, flake8
88

99
[testenv]
10-
passenv = DISPLAY PYTEST_ADDOPTS
10+
passenv = PYTEST_ADDOPTS
1111
setenv = MOZ_HEADLESS=1
1212
deps =
1313
pytest-localserver

0 commit comments

Comments
 (0)