Skip to content

Commit

Permalink
Use chrome and firefox in headless mode (#221)
Browse files Browse the repository at this point in the history
* Use chrome and firefox in headless mode

* Fix geckodriver script to be more linux friendly

* Docs and final travis.yml touches
  • Loading branch information
BeyondEvil committed Jun 5, 2019
1 parent a26c408 commit ee2cbdf
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__
.idea
.pytest_cache
.tox
.vscode/
*.egg-info/
*.pyc
build
Expand Down
39 changes: 18 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
language: python
jobs:
include:
- stage:
- stage: Linting
python: 3.7
dist: xenial
sudo: required
before_install: skip
addons: skip
env: TOXENV=flake8

- stage:
- stage: Docs
python: 3.7
dist: xenial
sudo: required
before_install: skip
addons: skip
env: TOXENV=docs

- stage:
- stage: python 2.7
python: 2.7
env: TOXENV=py27
services:
- xvfb

- stage:
- stage: python 3.6
python: 3.6
env: TOXENV=py36
services:
- xvfb

- stage:
- stage: python 3.7
python: 3.7
dist: xenial
sudo: required
env: TOXENV=py37
services:
- xvfb

- stage:
- stage: pypy 5.6.0
python: pypy-5.6.0
env: TOXENV=pypy
services:
- xvfb

- stage: deploy
python: 3.7
Expand All @@ -46,6 +42,7 @@ jobs:
before_install: skip
install: skip
script: skip
addons: skip
deploy:
provider: pypi
user: davehunt
Expand All @@ -60,21 +57,21 @@ sudo: required

env:
global:
- DISPLAY=:99.0
- GECKODRIVER_VERSION=0.21.0
- PYTEST_ADDOPTS="-m 'not (chrome or edge or safari or phantomjs)'"
- PYTEST_ADDOPTS="-m 'not (edge or safari or phantomjs)'"
- GECKODRIVER_FALLBACK_VERSION="v0.24.0"

cache: pip

before_install:
- curl -L -o /tmp/geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/v$GECKODRIVER_VERSION/geckodriver-v$GECKODRIVER_VERSION-linux64.tar.gz
- mkdir $HOME/geckodriver && tar xvf /tmp/geckodriver.tar.gz -C $HOME/geckodriver
- export PATH=$HOME/geckodriver:$PATH
- geckodriver --version
- sudo apt-get update
- sudo apt-get install -y curl jq
- sudo installation/geckodriver.sh latest
- sudo installation/chromedriver.sh latest

install: pip install tox

script: tox

addons:
firefox: latest
chrome: stable
36 changes: 36 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,39 @@ against the supported Python versions.
$ pip install tox
$ tox
Drivers
-------
To run the tests you'll going to need some browser drivers.

Chromedriver
~~~~~~~~~~~~
To install the latest `chromedriver <https://sites.google.com/a/chromium.org/chromedriver/>`_
on your Mac or Linux (64-bit), run:

.. code-block:: bash
$ ./installation/chromedriver.sh
For Windows users, please see `here <https://sites.google.com/a/chromium.org/chromedriver/getting-started>`_.

Geckodriver
~~~~~~~~~~~
To install the latest `geckodriver <https://firefox-source-docs.mozilla.org/testing/geckodriver/>`_
on your Mac or Linux (64-bit), run:

.. code-block:: bash
$ ./installation/geckodriver.sh
Safaridriver
~~~~~~~~~~~~
Instructions for `safaridriver <https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?language=objc>`_.

Edgedriver
~~~~~~~~~~
Instructions for `edgedriver <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads>`_.

IEDriver
~~~~~~~~
Instructions for `iedriver <https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver>`_.
22 changes: 22 additions & 0 deletions installation/chromedriver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

version=${1:-latest}

install_dir="/usr/local/bin"
drivername="chromedriver"
base_url="https://${drivername}.storage.googleapis.com"

[[ ${version} == "latest" ]] && version=$(curl -s "${base_url}/LATEST_RELEASE")

[[ $(uname) == "Darwin" ]] && os="mac" || os="linux"

filename="${drivername}_${os}64.zip"
curl -sL -o /tmp/"${filename}" "${base_url}/${version}/${filename}"
unzip -q /tmp/"${filename}"
mv ${drivername} "${install_dir}"

[[ $(uname) == "Linux" ]] && chmod +x "${install_dir}/${drivername}"

echo "${drivername} ${version} is now available in '${install_dir}'"
26 changes: 26 additions & 0 deletions installation/geckodriver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

version=${1:-latest}

install_dir="/usr/local/bin"
base_url="https://github.com/mozilla/geckodriver/releases/download"

if [[ ${version} == "latest" ]]; then
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
version=$(echo "${json}" | jq -r '.tag_name')
# In case of "API rate limit exceeded"
# See https://developer.github.com/v3/#rate-limiting
[[ ${version} == "null" ]] && version=${GECKODRIVER_FALLBACK_VERSION}
else
version="v${version}"
fi

[[ $(uname) == "Darwin" ]] && os="macos" || os="linux64"

filename="geckodriver-${version}-${os}.tar.gz"
curl -sL -o /tmp/"${filename}" "${base_url}/${version}/${filename}"
tar -xf /tmp/"${filename}" -C "${install_dir}"
rm /tmp/"${filename}"
echo "geckodriver ${version} is now available in '${install_dir}'"
14 changes: 11 additions & 3 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ def testdir(request, httpserver_base_url):

testdir = request.getfixturevalue("testdir")

testdir.makepyfile(
conftest="""
conftest = """
import pytest
@pytest.fixture
def webtext(base_url, selenium):
selenium.get(base_url)
return selenium.find_element_by_tag_name('h1').text
"""
)

if item.get_closest_marker("chrome"):
conftest += """
@pytest.fixture
def chrome_options(chrome_options):
chrome_options.add_argument("headless")
return chrome_options
"""

testdir.makepyfile(conftest=conftest)

testdir.makefile(
".cfg",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
envlist = py{27,36,37,py,py3}, docs, flake8

[testenv]
passenv = DISPLAY PYTEST_ADDOPTS
passenv = PYTEST_ADDOPTS
setenv = MOZ_HEADLESS=1
deps =
pytest-localserver
Expand Down

0 comments on commit ee2cbdf

Please sign in to comment.