Skip to content

Commit

Permalink
build: Run tests using Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil committed Oct 31, 2022
1 parent 47f4ef3 commit 0490870
Show file tree
Hide file tree
Showing 24 changed files with 332 additions and 109 deletions.
38 changes: 20 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ 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: Spin up Grid
run: ./start
# - 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: Cache tox environments
uses: actions/cache@v3
Expand All @@ -70,7 +72,7 @@ jobs:

- name: Test
if: matrix.os == 'ubuntu-latest'
run: tox -e ${{ matrix.tox_env }}
run: tox -e ${{ matrix.tox_env }} -- --html={envlogdir}/report.html --self-contained-html

- name: Test (skip firefox on windows)
if: matrix.os == 'windows-latest'
Expand Down
61 changes: 61 additions & 0 deletions docker-compose.arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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:latest
container_name: selenium-chromium
shm_size: 2gb
ports:
- "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:latest
container_name: selenium-firefox
shm_size: 2gb
ports:
- "7903: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

selenium-hub:
image: seleniarm/hub:latest
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:
77 changes: 77 additions & 0 deletions docker-compose.intel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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:

chrome:
image: selenium/node-chrome:latest
container_name: selenium-chrome
shm_size: 2gb
ports:
- "5901: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

edge:
image: selenium/node-edge:latest
container_name: selenium-edge
shm_size: 2gb
ports:
- "5902: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

firefox:
image: selenium/node-firefox:latest
container_name: selenium-firefox
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

selenium-hub:
image: selenium/hub:latest
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
- chrome
- edge

networks:
grid:
14 changes: 14 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 .

CMD ["flask", "run"]
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>"""
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ black = ">=22.1.0"
flake8 = ">=4.0.1"
tox = ">=3.24.5"
pre-commit = ">=2.17.0"
pytest-localserver = ">=0.5.0"
pytest-xdist = ">=2.4.0"
pytest-mock = ">=3.6.1"

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_selenium/drivers/browserstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def job_access(self):
return field


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_runtest_makereport(item, report, summary, extra):
provider = BrowserStack()
if not provider.uses_driver(item.config.getoption("driver")):
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_selenium/drivers/crossbrowsertesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def key(self):
)


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_capture_debug(item, report, extra):
provider = CrossBrowserTesting()
if not provider.uses_driver(item.config.getoption("driver")):
Expand All @@ -57,7 +57,7 @@ def pytest_selenium_capture_debug(item, report, extra):
extra.append(pytest_html.extras.html(_video_html(videos[0])))


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_runtest_makereport(item, report, summary, extra):
provider = CrossBrowserTesting()
if not provider.uses_driver(item.config.getoption("driver")):
Expand Down
7 changes: 7 additions & 0 deletions src/pytest_selenium/drivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import os

# from selenium.webdriver.chrome.options import Options

HOST = os.environ.get("SELENIUM_HOST", "localhost")
PORT = os.environ.get("SELENIUM_PORT", 4444)

Expand All @@ -12,8 +14,13 @@ def driver_kwargs(capabilities, host, port, **kwargs):
host = host if host.startswith("http") else f"http://{host}"
executor = f"{host}:{port}/wd/hub"

# options = Options()
# options.add_argument("--log-path=foo.log")
# print(options.to_capabilities())

kwargs = {
"command_executor": executor,
"desired_capabilities": capabilities,
# "options": options,
}
return kwargs
4 changes: 2 additions & 2 deletions src/pytest_selenium/drivers/saucelabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def uses_driver(self, driver):
return driver.lower() == self.name.lower()


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_capture_debug(item, report, extra):
provider = SauceLabs(item.config.getini("saucelabs_data_center"))
if not provider.uses_driver(item.config.getoption("driver")):
Expand All @@ -62,7 +62,7 @@ def pytest_selenium_capture_debug(item, report, extra):
extra.append(pytest_html.extras.html(_video_html(item._driver.session_id)))


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_runtest_makereport(item, report, summary, extra):
provider = SauceLabs(item.config.getini("saucelabs_data_center"))
if not provider.uses_driver(item.config.getoption("driver")):
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_selenium/drivers/testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def secret(self):
return self.get_credential("secret", ["TESTINGBOT_SECRET", "TESTINGBOT_PSW"])


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_capture_debug(item, report, extra):
provider = TestingBot()
if not provider.uses_driver(item.config.getoption("driver")):
Expand All @@ -56,7 +56,7 @@ def pytest_selenium_capture_debug(item, report, extra):
extra.append(pytest_html.extras.html(_video_html(auth_url, session_id)))


@pytest.mark.optionalhook
@pytest.hookimpl(optionalhook=True)
def pytest_selenium_runtest_makereport(item, report, summary, extra):
provider = TestingBot()
if not provider.uses_driver(item.config.getoption("driver")):
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def pytest_report_header(config, startdir):
return "driver: {0}".format(driver)


@pytest.mark.hookwrapper
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
Expand Down
11 changes: 11 additions & 0 deletions start
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ $(uname -m) == "arm64" ]]; then
arch="arm"
else
arch="intel"
fi

docker-compose -f "docker-compose.${arch}.yml" up -d
11 changes: 11 additions & 0 deletions stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ $(uname -m) == "arm64" ]]; then
arch="arm"
else
arch="intel"
fi

docker-compose -f "docker-compose.${arch}.yml" down
27 changes: 21 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,21 +59,36 @@ 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

def quick_qa(*args, **kwargs):
reprec = inline_runqa(*args)
outcomes = reprec.listoutcomes()
print(f"outcomes: {outcomes}")
names = ("passed", "skipped", "failed")
for name, val in zip(names, outcomes):
wantlen = kwargs.get(name)
Expand Down
Loading

0 comments on commit 0490870

Please sign in to comment.