Skip to content

Commit

Permalink
Fix Safari runner initialization in selenium >= 4.20 (#135)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ryanking13 and pre-commit-ci[bot] committed Apr 30, 2024
1 parent 0b78ac0 commit f957dcd
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
build-artifact-name: none
build-artifact-path: none
pyodide-versions: "0.24.1,0.23.4"
pyodide-versions: "0.25.1,0.24.1,0.23.4"

deploy:
runs-on: ubuntu-20.04
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ jobs:
# Currently we only install the package for dependencies.
# We then uninstall it otherwise tests fails due to pytest hook being
# registered twice.
${{needs.get_versions.outputs.pythonexec}} -m pip install ".[test]"
# temporarily pin pytest version (https://github.com/pyodide/pytest-pyodide/pull/133#issuecomment-2081412407)
${{needs.get_versions.outputs.pythonexec}} -m pip install ".[test]" "pytest<8.0.0"
else
${{needs.get_versions.outputs.pythonexec}} -m pip install pytest-pyodide
fi
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.57.0] - 2024-04-30

- Fixed safari compatibility with Selenium 4.20
[#135](https://github.com/pyodide/pytest-pyodide/pull/135)

## [0.56.1] - 2023-12-09

Expand Down
5 changes: 3 additions & 2 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Following versions of pytest-pyodide and Pyodide are tested in CI.
Other versions may work, however with no guarantee.

| pytest-pyodide | Tested Pyodide versions |
| -------------- | ----------------------- |
| main branch | 0.23.4, 0.24.1 |
|----------------|-------------------------|
| main branch | 0.23.4, 0.24.1, 0.25.1 |
| 0.57.* | 0.23.4, 0.24.1, 0.25.1 |
| 0.56.* | 0.23.4, 0.24.1 |
| 0.55.* | 0.23.4, 0.24.1 |
| 0.54.* | 0.23.4, 0.24.1 |
Expand Down
3 changes: 3 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pytest_plugins = [
"pytester",
]

# importing this fixture has a side effect of making the safari webdriver reused during the session
from pytest_pyodide.runner import use_global_safari_service # noqa: F401
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ python_version = "3.10"
show_error_codes = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
disable_error_code = ["attr-defined"]

# Strict checks
warn_unused_configs = true
Expand Down
2 changes: 1 addition & 1 deletion pytest_pyodide/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def package_is_built(package_name: str):
return _package_is_built(package_name, pytest.pyodide_dist_dir) # type: ignore[arg-type]
return _package_is_built(package_name, pytest.pyodide_dist_dir)


class SeleniumType(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion pytest_pyodide/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _playwright_browsers(request):
# "webkit": (),
}
try:
for runtime in runtimes: # type: ignore[attr-defined]
for runtime in runtimes:
if runtime not in supported_browsers:
pytest.exit(
f"Unsupported runtime for playwright: {runtime}",
Expand Down
2 changes: 1 addition & 1 deletion pytest_pyodide/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def pytest_configure(config):
if not hasattr(pytest, "pyodide_options_stack"):
pytest.pyodide_options_stack = []
else:
pytest.pyodide_options_stack.append( # type:ignore[attr-defined]
pytest.pyodide_options_stack.append(
[
pytest.pyodide_run_host_test,
pytest.pyodide_runtimes,
Expand Down
16 changes: 12 additions & 4 deletions pytest_pyodide/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,25 @@ def collect_garbage(self):

@pytest.fixture(scope="session", autouse=True)
def use_global_safari_service():
if "safari" in pytest.pyodide_runtimes: # type: ignore[operator]
if "safari" in pytest.pyodide_runtimes:
global GLOBAL_SAFARI_WEBDRIVER

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.safari.options import Options
from selenium.webdriver.safari.service import Service

GLOBAL_SAFARI_WEBDRIVER = Service(reuse_service=True)
GLOBAL_SAFARI_WEBDRIVER.path = DriverFinder.get_path(
GLOBAL_SAFARI_WEBDRIVER, Options()
)

try:
# selenium >= 4.20
# https://github.com/SeleniumHQ/selenium/pull/13387
finder = DriverFinder(GLOBAL_SAFARI_WEBDRIVER, Options())
browser_path = finder.get_driver_path()
except Exception:
# selenium < 4.20
browser_path = DriverFinder.get_path(GLOBAL_SAFARI_WEBDRIVER, Options())

GLOBAL_SAFARI_WEBDRIVER.path = browser_path
GLOBAL_SAFARI_WEBDRIVER.start()

try:
Expand Down
2 changes: 1 addition & 1 deletion utils/build_test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULT_BROWSER = "chrome, firefox, node, safari, host"
DEFAULT_CHROME_VERSION = "latest"
DEFAULT_FIREFOX_VERSION = "latest"
DEFAULT_NODE_VERSION = "18, 20"
DEFAULT_NODE_VERSION = "20"
DEFAULT_PLAYWRIGHT_VERSION = (
"1.22.0" # TODO: versions > 1.22.0 have firefox performance issue
)
Expand Down

0 comments on commit f957dcd

Please sign in to comment.