diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index 51c2723c4ac35..a4a8edd5366fe 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + import json import logging import os @@ -55,13 +56,20 @@ def binary_paths(self, args: list) -> dict: @staticmethod def _get_binary() -> Path: - """Determines the path of the correct Selenium Manager binary. + """Determines the path of the Selenium Manager binary. + + Location of the binary is checked in this order: + + 1. location set in an environment variable + 2. location where setuptools-rust places the compiled binary (built from the sdist package) + 3. location where we ship binaries in the wheel package for the platform this is running on + 4. give up Returns: The Selenium Manager executable location. Raises: - WebDriverException: If the platform is unsupported. + WebDriverException: If the platform is unsupported or Selenium Manager executable can't be found. """ compiled_path = Path(__file__).parent.joinpath("selenium-manager") exe = sysconfig.get_config_var("EXE") @@ -71,9 +79,12 @@ def _get_binary() -> Path: path: Path | None = None if (env_path := os.getenv("SE_MANAGER_PATH")) is not None: - logger.debug("Selenium Manager set by env SE_MANAGER_PATH to: %s", env_path) - path = Path(env_path) - elif compiled_path.exists(): + logger.debug(f"Selenium Manager set by env SE_MANAGER_PATH to: {env_path}") + path_candidate = Path(env_path) + if not path_candidate.is_file(): + raise WebDriverException(f"SE_MANAGER_PATH does not point to a file: {env_path}") + path = path_candidate + elif compiled_path.is_file(): path = compiled_path else: allowed = { @@ -87,7 +98,7 @@ def _get_binary() -> Path: arch = platform.machine() if sys.platform in ("linux", "freebsd", "openbsd") else "any" if sys.platform in ["freebsd", "openbsd"]: - logger.warning("Selenium Manager binary may not be compatible with %s; verify settings", sys.platform) + logger.warning(f"Selenium Manager binary may not be compatible with {sys.platform}; verify settings") location = allowed.get((sys.platform, arch)) if location is None: @@ -98,7 +109,7 @@ def _get_binary() -> Path: if path is None or not path.is_file(): raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}") - logger.debug("Selenium Manager binary found at: %s", path) + logger.debug(f"Selenium Manager binary found at: {path}") return path diff --git a/py/test/selenium/webdriver/common/selenium_manager_tests.py b/py/test/selenium/webdriver/common/selenium_manager_tests.py index 5a70faab1e499..13edd5577ce7f 100644 --- a/py/test/selenium/webdriver/common/selenium_manager_tests.py +++ b/py/test/selenium/webdriver/common/selenium_manager_tests.py @@ -108,7 +108,7 @@ def test_error_if_invalid_env_path(monkeypatch): with pytest.raises(WebDriverException) as excinfo: SeleniumManager()._get_binary() - assert f"Unable to obtain working Selenium Manager binary; {sm_path}" in str(excinfo.value) + assert f"SE_MANAGER_PATH does not point to a file: {sm_path}" in str(excinfo.value) def test_run_successful():