Repository: pyodide/pytest-pyodide (language: python)

Issue:
AttributeError: type object 'DriverFinder' has no attribute 'get_path'
Seems like there is some change in selenium.

```
../miniforge3/envs/pyodide/lib/python3.12/site-packages/pytest_pyodide/runner.py:476: in use_global_safari_service
    GLOBAL_SAFARI_WEBDRIVER.path = DriverFinder.get_path(
E   AttributeError: type object 'DriverFinder' has no attribute 'get_path'
```


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index c9fad409..cfd710ee 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -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
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index c60e0fe5..fc3b6e1e 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 499e5baa..91dccd7f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
 
diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md
index d098601b..c28adc5d 100644
--- a/COMPATIBILITY.md
+++ b/COMPATIBILITY.md
@@ -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          |
diff --git a/pyproject.toml b/pyproject.toml
index dddf8274..7a80dbf9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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


Test patch:
diff --git a/conftest.py b/conftest.py
index a4e71f15..c68326bb 100644
--- a/conftest.py
+++ b/conftest.py
@@ -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
diff --git a/pytest_pyodide/decorator.py b/pytest_pyodide/decorator.py
index 33580018..5aef6582 100644
--- a/pytest_pyodide/decorator.py
+++ b/pytest_pyodide/decorator.py
@@ -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):
diff --git a/pytest_pyodide/fixture.py b/pytest_pyodide/fixture.py
index 6ffd78a1..ea1485d7 100644
--- a/pytest_pyodide/fixture.py
+++ b/pytest_pyodide/fixture.py
@@ -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}",
diff --git a/pytest_pyodide/hook.py b/pytest_pyodide/hook.py
index 5a63d9ca..70e435f9 100644
--- a/pytest_pyodide/hook.py
+++ b/pytest_pyodide/hook.py
@@ -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,
diff --git a/pytest_pyodide/runner.py b/pytest_pyodide/runner.py
index b949a470..f60b046f 100644
--- a/pytest_pyodide/runner.py
+++ b/pytest_pyodide/runner.py
@@ -465,7 +465,7 @@ 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
@@ -473,9 +473,17 @@ def use_global_safari_service():
         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:
diff --git a/utils/build_test_matrix.py b/utils/build_test_matrix.py
index 006b3e52..184c28f2 100644
--- a/utils/build_test_matrix.py
+++ b/utils/build_test_matrix.py
@@ -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
 )