Skip to content

Chore: Run tests using docker #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 8 additions & 41 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ ! contains(github.ref, github.event.repository.default_branch) }}

env:
PYTEST_ADDOPTS: "-m 'not (edge or safari)'"

jobs:
linting:
runs-on: ubuntu-latest
Expand All @@ -37,28 +34,20 @@ jobs:
run: tox -e linting

test:
name: ${{ matrix.os }} - ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
name: ubuntu-latest - ${{ matrix.tox-env || matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
include:
- os: ubuntu-latest
python-version: pypy3.9
tox-env: py3.9
- os: windows-latest
python-version: pypy3.9
tox-env: py3.9

# TODO(jim) Deactivate devel tests pending troubleshooting
# - os: ubuntu-latest
# python-version: 3.12-dev
# tox-env: devel
# - os: windows-latest
# python-version: 3.12-dev
# tox-env: devel
- os: ubuntu-latest
python-version: 3.11
tox-env: devel

steps:
- uses: actions/checkout@v3
Expand All @@ -73,23 +62,8 @@ jobs:
python -m pip install --upgrade pip
pip install tox

- name: Setup Firefox
if: matrix.os == 'ubuntu-latest'
uses: browser-actions/setup-firefox@latest
with:
firefox-version: latest

- name: Setup Geckodriver
if: matrix.os == 'ubuntu-latest'
uses: browser-actions/setup-geckodriver@latest

- name: Setup Chrome
uses: browser-actions/setup-chrome@latest
with:
chrome-version: stable

- name: Setup Chromedriver
uses: nanasess/setup-chromedriver@master
- name: Start browsers
run: docker/start

- name: Cache tox environments
uses: actions/cache@v3
Expand All @@ -111,13 +85,6 @@ jobs:
fi

- name: Test
if: matrix.os == 'ubuntu-latest'
run: tox -e "${{ env.tox }}"

- name: Test (skip firefox on windows)
if: matrix.os == 'windows-latest'
env:
PYTEST_ADDOPTS: "-m 'not (edge or safari or firefox)'"
run: tox -e "${{ env.tox }}"

- name: Archive report.html
Expand Down
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.10-slim-buster

WORKDIR /usr/src/app

ENV FLASK_APP=webserver.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_RUN_PORT=80

RUN python -m pip install --upgrade pip && \
pip install flask

COPY webserver.py .

ENTRYPOINT ["flask"]
CMD ["run"]
80 changes: 80 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# To execute this docker-compose yml file use `docker-compose -f docker-compose.intel.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3.yml down`
version: "3"

services:

chromium:
image: seleniarm/node-chromium:113.0
container_name: selenium-chromium
shm_size: 2gb
ports:
- "5901:5900"
- "7901:7900"
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
networks:
- grid

firefox:
image: seleniarm/node-firefox:112.0
container_name: selenium-firefox
shm_size: 2gb
ports:
- "5902:5900"
- "7902:7900"
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
networks:
- grid

edge:
image: selenium/node-edge:113.0
container_name: selenium-edge
shm_size: 2gb
ports:
- "5903:5900"
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
networks:
- grid
profiles:
- intel

selenium-hub:
image: seleniarm/hub:4.9.1
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
networks:
- grid

webserver:
container_name: webserver
build:
context: docker
environment:
- PYTHONDONTWRITEBYTECODE=1
networks:
- grid
depends_on:
- firefox
- chromium

networks:
grid:
12 changes: 12 additions & 0 deletions docker/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

if [[ "${1}" == "down" ]]; then
docker compose --file docker/docker-compose.yml down
exit 0
fi

if [[ $(uname -m) == "arm64" ]]; then
docker compose --file docker/docker-compose.yml up -d
else
docker compose --file docker/docker-compose.yml --profile intel up -d
fi
8 changes: 8 additions & 0 deletions docker/webserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask

app = Flask(__name__)


@app.route("/")
def home():
return """<h1>Success!</h1><a href="#">Link</a><p>Ё</p>"""
33 changes: 11 additions & 22 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,28 @@ Otherwise, to install and run, do:

Drivers
-------
To run the tests you're 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:
The tests requires that Docker is available and uses the Selenium/Seleniarm containerized browsers and drivers.

.. code-block:: bash
Read more here: `Docker-Seleniarm <https://github.com/seleniumhq-community/docker-seleniarm>`_

To start the browsers (and drivers):

$ ./installation/chromedriver.sh
.. code-block:: bash

For Windows users, please see `here <https://sites.google.com/a/chromium.org/chromedriver/getting-started>`_.
$ docker/start

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

.. code-block:: bash

$ ./installation/geckodriver.sh
$ docker ps

Safaridriver
~~~~~~~~~~~~
Instructions for `safaridriver <https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?language=objc>`_.
To stop the containers, run:

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

IEDriver
~~~~~~~~
Instructions for `iedriver <https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver>`_.
$ docker/start down

Releasing a new version
-----------------------
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dynamic = [
[project.optional-dependencies]
appium = [ "appium-python-client>=1.0.0" ]
test = [
"pytest-localserver>=0.5.0",
"pytest-xdist>=2.4.0",
"pytest-mock>=3.6.1",
"black>=22.1.0",
Expand Down
26 changes: 20 additions & 6 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
pytest_plugins = "pytester"


def base_url(httpserver):
return httpserver.url
def base_url():
return "http://webserver"


@pytest.fixture
def httpserver_base_url(httpserver):
return "--base-url={0}".format(base_url(httpserver))
def httpserver_base_url():
return "--base-url={0}".format(base_url())


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -59,14 +59,28 @@ def chrome_options(chrome_options):

def runpytestqa(*args, **kwargs):
return testdir.runpytest(
httpserver_base_url, "--driver", "Firefox", *args, **kwargs
httpserver_base_url,
"--driver",
"remote",
"--capability",
"browserName",
"firefox",
*args,
**kwargs,
)

testdir.runpytestqa = runpytestqa

def inline_runqa(*args, **kwargs):
return testdir.inline_run(
httpserver_base_url, "--driver", "Firefox", *args, **kwargs
httpserver_base_url,
"--driver",
"remote",
"--capability",
"browserName",
"firefox",
*args,
**kwargs,
)

testdir.inline_runqa = inline_runqa
Expand Down
28 changes: 23 additions & 5 deletions testing/test_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


@pytest.mark.chrome
def test_launch(testdir, httpserver):
httpserver.serve_content(content="<h1>Success!</h1>")
def test_launch(testdir):
file_test = testdir.makepyfile(
"""
import pytest
Expand All @@ -20,7 +19,15 @@ def test_pass(webtext):
assert webtext == u'Success!'
"""
)
testdir.quick_qa("--driver", "Chrome", file_test, passed=1)
testdir.quick_qa(
"--driver",
"Remote",
"--capability",
"browserName",
"chrome",
file_test,
passed=1,
)


@pytest.mark.chrome
Expand All @@ -37,13 +44,16 @@ def chrome_options(chrome_options):
def test_pass(selenium): pass
"""
)
reprec = testdir.inline_run("--driver", "Chrome")
reprec = testdir.inline_run(
"--driver", "Remote", "--capability", "browserName", "chrome"
)
passed, skipped, failed = reprec.listoutcomes()
assert len(failed) == 1
out = failed[0].longrepr.reprcrash.message
assert "no chrome binary at /foo/bar" in out


@pytest.mark.xfail(reason="Remote driver currently doesn't support logs")
@pytest.mark.chrome
def test_args(testdir):
file_test = testdir.makepyfile(
Expand All @@ -61,5 +71,13 @@ def driver_args():
def test_pass(selenium): pass
"""
)
testdir.quick_qa("--driver", "Chrome", file_test, passed=1)
testdir.quick_qa(
"--driver",
"Remote",
"--capability",
"browserName",
"chrome",
file_test,
passed=1,
)
assert os.path.exists(str(testdir.tmpdir.join("foo.log")))
Loading