Skip to content

Commit 7d4422f

Browse files
authored
Chore: Run tests using docker (#309)
1 parent d381f8b commit 7d4422f

19 files changed

+247
-178
lines changed

.github/workflows/test.yml

+8-41
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ concurrency:
1414
group: ${{ github.workflow }}-${{ github.ref }}
1515
cancel-in-progress: ${{ ! contains(github.ref, github.event.repository.default_branch) }}
1616

17-
env:
18-
PYTEST_ADDOPTS: "-m 'not (edge or safari)'"
19-
2017
jobs:
2118
linting:
2219
runs-on: ubuntu-latest
@@ -37,28 +34,20 @@ jobs:
3734
run: tox -e linting
3835

3936
test:
40-
name: ${{ matrix.os }} - ${{ matrix.python-version }}
41-
runs-on: ${{ matrix.os }}
37+
name: ubuntu-latest - ${{ matrix.tox-env || matrix.python-version }}
38+
runs-on: ubuntu-latest
4239
strategy:
43-
fail-fast: true
40+
fail-fast: false
4441
matrix:
45-
os: [ubuntu-latest, windows-latest]
4642
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
4743
include:
4844
- os: ubuntu-latest
4945
python-version: pypy3.9
5046
tox-env: py3.9
51-
- os: windows-latest
52-
python-version: pypy3.9
53-
tox-env: py3.9
5447

55-
# TODO(jim) Deactivate devel tests pending troubleshooting
56-
# - os: ubuntu-latest
57-
# python-version: 3.12-dev
58-
# tox-env: devel
59-
# - os: windows-latest
60-
# python-version: 3.12-dev
61-
# tox-env: devel
48+
- os: ubuntu-latest
49+
python-version: 3.11
50+
tox-env: devel
6251

6352
steps:
6453
- uses: actions/checkout@v3
@@ -73,23 +62,8 @@ jobs:
7362
python -m pip install --upgrade pip
7463
pip install tox
7564
76-
- name: Setup Firefox
77-
if: matrix.os == 'ubuntu-latest'
78-
uses: browser-actions/setup-firefox@latest
79-
with:
80-
firefox-version: latest
81-
82-
- name: Setup Geckodriver
83-
if: matrix.os == 'ubuntu-latest'
84-
uses: browser-actions/setup-geckodriver@latest
85-
86-
- name: Setup Chrome
87-
uses: browser-actions/setup-chrome@latest
88-
with:
89-
chrome-version: stable
90-
91-
- name: Setup Chromedriver
92-
uses: nanasess/setup-chromedriver@master
65+
- name: Start browsers
66+
run: docker/start
9367

9468
- name: Cache tox environments
9569
uses: actions/cache@v3
@@ -111,13 +85,6 @@ jobs:
11185
fi
11286
11387
- name: Test
114-
if: matrix.os == 'ubuntu-latest'
115-
run: tox -e "${{ env.tox }}"
116-
117-
- name: Test (skip firefox on windows)
118-
if: matrix.os == 'windows-latest'
119-
env:
120-
PYTEST_ADDOPTS: "-m 'not (edge or safari or firefox)'"
12188
run: tox -e "${{ env.tox }}"
12289

12390
- name: Archive report.html

docker/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.10-slim-buster
2+
3+
WORKDIR /usr/src/app
4+
5+
ENV FLASK_APP=webserver.py
6+
ENV FLASK_RUN_HOST=0.0.0.0
7+
ENV FLASK_RUN_PORT=80
8+
9+
RUN python -m pip install --upgrade pip && \
10+
pip install flask
11+
12+
COPY webserver.py .
13+
14+
ENTRYPOINT ["flask"]
15+
CMD ["run"]

docker/docker-compose.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# To execute this docker-compose yml file use `docker-compose -f docker-compose.intel.yml up`
2+
# Add the `-d` flag at the end for detached execution
3+
# To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3.yml down`
4+
version: "3"
5+
6+
services:
7+
8+
chromium:
9+
image: seleniarm/node-chromium:113.0
10+
container_name: selenium-chromium
11+
shm_size: 2gb
12+
ports:
13+
- "5901:5900"
14+
- "7901:7900"
15+
depends_on:
16+
- selenium-hub
17+
environment:
18+
- SE_EVENT_BUS_HOST=selenium-hub
19+
- SE_EVENT_BUS_PUBLISH_PORT=4442
20+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
21+
networks:
22+
- grid
23+
24+
firefox:
25+
image: seleniarm/node-firefox:112.0
26+
container_name: selenium-firefox
27+
shm_size: 2gb
28+
ports:
29+
- "5902:5900"
30+
- "7902:7900"
31+
depends_on:
32+
- selenium-hub
33+
environment:
34+
- SE_EVENT_BUS_HOST=selenium-hub
35+
- SE_EVENT_BUS_PUBLISH_PORT=4442
36+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
37+
networks:
38+
- grid
39+
40+
edge:
41+
image: selenium/node-edge:113.0
42+
container_name: selenium-edge
43+
shm_size: 2gb
44+
ports:
45+
- "5903:5900"
46+
depends_on:
47+
- selenium-hub
48+
environment:
49+
- SE_EVENT_BUS_HOST=selenium-hub
50+
- SE_EVENT_BUS_PUBLISH_PORT=4442
51+
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
52+
networks:
53+
- grid
54+
profiles:
55+
- intel
56+
57+
selenium-hub:
58+
image: seleniarm/hub:4.9.1
59+
container_name: selenium-hub
60+
ports:
61+
- "4442:4442"
62+
- "4443:4443"
63+
- "4444:4444"
64+
networks:
65+
- grid
66+
67+
webserver:
68+
container_name: webserver
69+
build:
70+
context: docker
71+
environment:
72+
- PYTHONDONTWRITEBYTECODE=1
73+
networks:
74+
- grid
75+
depends_on:
76+
- firefox
77+
- chromium
78+
79+
networks:
80+
grid:

docker/start

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "${1}" == "down" ]]; then
4+
docker compose --file docker/docker-compose.yml down
5+
exit 0
6+
fi
7+
8+
if [[ $(uname -m) == "arm64" ]]; then
9+
docker compose --file docker/docker-compose.yml up -d
10+
else
11+
docker compose --file docker/docker-compose.yml --profile intel up -d
12+
fi

docker/webserver.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
6+
@app.route("/")
7+
def home():
8+
return """<h1>Success!</h1><a href="#">Link</a><p>Ё</p>"""

docs/development.rst

+11-22
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,28 @@ Otherwise, to install and run, do:
4747
4848
Drivers
4949
-------
50-
To run the tests you're going to need some browser drivers.
5150

52-
Chromedriver
53-
~~~~~~~~~~~~
54-
To install the latest `chromedriver <https://sites.google.com/a/chromium.org/chromedriver/>`_
55-
on your Mac or Linux (64-bit), run:
51+
The tests requires that Docker is available and uses the Selenium/Seleniarm containerized browsers and drivers.
5652

57-
.. code-block:: bash
53+
Read more here: `Docker-Seleniarm <https://github.com/seleniumhq-community/docker-seleniarm>`_
54+
55+
To start the browsers (and drivers):
5856

59-
$ ./installation/chromedriver.sh
57+
.. code-block:: bash
6058
61-
For Windows users, please see `here <https://sites.google.com/a/chromium.org/chromedriver/getting-started>`_.
59+
$ docker/start
6260
63-
Geckodriver
64-
~~~~~~~~~~~
65-
To install the latest `geckodriver <https://firefox-source-docs.mozilla.org/testing/geckodriver/>`_
66-
on your Mac or Linux (64-bit), run:
61+
You can check status by running:
6762

6863
.. code-block:: bash
6964
70-
$ ./installation/geckodriver.sh
65+
$ docker ps
7166
72-
Safaridriver
73-
~~~~~~~~~~~~
74-
Instructions for `safaridriver <https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?language=objc>`_.
67+
To stop the containers, run:
7568

76-
Edgedriver
77-
~~~~~~~~~~
78-
Instructions for `edgedriver <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads>`_.
69+
.. code-block:: bash
7970
80-
IEDriver
81-
~~~~~~~~
82-
Instructions for `iedriver <https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver>`_.
71+
$ docker/start down
8372
8473
Releasing a new version
8574
-----------------------

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ dynamic = [
5959
[project.optional-dependencies]
6060
appium = [ "appium-python-client>=1.0.0" ]
6161
test = [
62-
"pytest-localserver>=0.5.0",
6362
"pytest-xdist>=2.4.0",
6463
"pytest-mock>=3.6.1",
6564
"black>=22.1.0",

testing/conftest.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
pytest_plugins = "pytester"
1010

1111

12-
def base_url(httpserver):
13-
return httpserver.url
12+
def base_url():
13+
return "http://webserver"
1414

1515

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

2020

2121
@pytest.fixture(autouse=True)
@@ -59,14 +59,28 @@ def chrome_options(chrome_options):
5959

6060
def runpytestqa(*args, **kwargs):
6161
return testdir.runpytest(
62-
httpserver_base_url, "--driver", "Firefox", *args, **kwargs
62+
httpserver_base_url,
63+
"--driver",
64+
"remote",
65+
"--capability",
66+
"browserName",
67+
"firefox",
68+
*args,
69+
**kwargs,
6370
)
6471

6572
testdir.runpytestqa = runpytestqa
6673

6774
def inline_runqa(*args, **kwargs):
6875
return testdir.inline_run(
69-
httpserver_base_url, "--driver", "Firefox", *args, **kwargs
76+
httpserver_base_url,
77+
"--driver",
78+
"remote",
79+
"--capability",
80+
"browserName",
81+
"firefox",
82+
*args,
83+
**kwargs,
7084
)
7185

7286
testdir.inline_runqa = inline_runqa

testing/test_chrome.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111

1212
@pytest.mark.chrome
13-
def test_launch(testdir, httpserver):
14-
httpserver.serve_content(content="<h1>Success!</h1>")
13+
def test_launch(testdir):
1514
file_test = testdir.makepyfile(
1615
"""
1716
import pytest
@@ -20,7 +19,15 @@ def test_pass(webtext):
2019
assert webtext == u'Success!'
2120
"""
2221
)
23-
testdir.quick_qa("--driver", "Chrome", file_test, passed=1)
22+
testdir.quick_qa(
23+
"--driver",
24+
"Remote",
25+
"--capability",
26+
"browserName",
27+
"chrome",
28+
file_test,
29+
passed=1,
30+
)
2431

2532

2633
@pytest.mark.chrome
@@ -37,13 +44,16 @@ def chrome_options(chrome_options):
3744
def test_pass(selenium): pass
3845
"""
3946
)
40-
reprec = testdir.inline_run("--driver", "Chrome")
47+
reprec = testdir.inline_run(
48+
"--driver", "Remote", "--capability", "browserName", "chrome"
49+
)
4150
passed, skipped, failed = reprec.listoutcomes()
4251
assert len(failed) == 1
4352
out = failed[0].longrepr.reprcrash.message
4453
assert "no chrome binary at /foo/bar" in out
4554

4655

56+
@pytest.mark.xfail(reason="Remote driver currently doesn't support logs")
4757
@pytest.mark.chrome
4858
def test_args(testdir):
4959
file_test = testdir.makepyfile(
@@ -61,5 +71,13 @@ def driver_args():
6171
def test_pass(selenium): pass
6272
"""
6373
)
64-
testdir.quick_qa("--driver", "Chrome", file_test, passed=1)
74+
testdir.quick_qa(
75+
"--driver",
76+
"Remote",
77+
"--capability",
78+
"browserName",
79+
"chrome",
80+
file_test,
81+
passed=1,
82+
)
6583
assert os.path.exists(str(testdir.tmpdir.join("foo.log")))

0 commit comments

Comments
 (0)