Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions py/selenium/webdriver/common/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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 = {
Expand All @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down