Skip to content

Commit

Permalink
Add android_chrome to tested browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcadman committed Dec 3, 2024
1 parent 4be353b commit b122029
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
run: appium driver doctor uiautomator2
- name: Run appium server in the background
run: appium --allow-insecure chromedriver_autodownload &
- name: Setup reverse proxy on Android Virtual Device
run: $ANDROID_HOME/platform-tools/adb reverse tcp:5000 tcp:5000
- name: Install python
uses: actions/setup-python@v5
with:
Expand Down
20 changes: 19 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from pathlib import Path

import pytest
from appium.options.android import UiAutomator2Options
from appium.webdriver import Remote
from appium.webdriver.appium_connection import AppiumConnection
from selenium import webdriver as wd
from selenium.webdriver.remote.client_config import ClientConfig


def chrome():
Expand Down Expand Up @@ -31,7 +35,21 @@ def firefox():
return wd.Firefox(**kwargs)


@pytest.fixture(params=[chrome, edge, firefox])
def android_chrome():
capabilities = dict(
platformName="Android",
browserName="chrome",
chromeOptions={"w3c": False},
)
appium_server_url = "http://localhost:4723"
client_config = ClientConfig(appium_server_url)
command_executor = AppiumConnection(client_config=client_config)
return Remote(
command_executor, options=UiAutomator2Options().load_capabilities(capabilities)
)


@pytest.fixture(params=[chrome, edge, firefox, android_chrome])
def driver(request):
with request.param() as _driver:
yield _driver
13 changes: 8 additions & 5 deletions tests/server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import signal
import subprocess as sp
import sys
import time
from contextlib import contextmanager

TIMEOUT = 5
PORT = 5000 # this matches the port in the reverse proxy command for Android Virtual Device


def close_server(server: sp.Popen, check_status=True):
Expand All @@ -16,10 +18,9 @@ def close_server(server: sp.Popen, check_status=True):

@contextmanager
def get_server_url(maintenance_mode: bool = False):
port = 5000
while True:
for _ in range(int(10 * TIMEOUT)):
server = sp.Popen(
[sys.executable, "run_flask.py", str(port), str(maintenance_mode)],
[sys.executable, "run_flask.py", str(PORT), str(maintenance_mode)],
stderr=sp.PIPE,
text=True,
universal_newlines=True,
Expand All @@ -29,10 +30,12 @@ def get_server_url(maintenance_mode: bool = False):
sys.stderr.write(out)
if "Address already in use" in out:
close_server(server, check_status=False)
port += 1
time.sleep(0.1)
else:
break
else:
raise TimeoutError(f"Could not start a webserver on port {PORT}")
try:
yield f"http://127.0.0.1:{port}"
yield f"http://127.0.0.1:{PORT}"
finally:
close_server(server)
36 changes: 0 additions & 36 deletions tests/test_appium.py

This file was deleted.

18 changes: 11 additions & 7 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from .server import get_server_url
import pytest

from . import server

def test_port_increment():
with get_server_url() as first_url:
first_port = int(first_url.split(":")[2])
with get_server_url() as second_url:
second_port = int(second_url.split(":")[2])
assert second_port > first_port

def test_timeout_error(monkeypatch):
with server.get_server_url():
monkeypatch.setattr(server, "TIMEOUT", 0.1)
with pytest.raises(
TimeoutError, match=f"Could not start a webserver on port {server.PORT}"
):
with server.get_server_url():
pass

0 comments on commit b122029

Please sign in to comment.