Skip to content

Commit 7284ec4

Browse files
authored
[py] Properly verify Selenium Manager exists (#16711)
1 parent ec3be09 commit 7284ec4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

py/selenium/webdriver/common/selenium_manager.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import json
1819
import logging
1920
import os
@@ -55,13 +56,20 @@ def binary_paths(self, args: list) -> dict:
5556

5657
@staticmethod
5758
def _get_binary() -> Path:
58-
"""Determines the path of the correct Selenium Manager binary.
59+
"""Determines the path of the Selenium Manager binary.
60+
61+
Location of the binary is checked in this order:
62+
63+
1. location set in an environment variable
64+
2. location where setuptools-rust places the compiled binary (built from the sdist package)
65+
3. location where we ship binaries in the wheel package for the platform this is running on
66+
4. give up
5967
6068
Returns:
6169
The Selenium Manager executable location.
6270
6371
Raises:
64-
WebDriverException: If the platform is unsupported.
72+
WebDriverException: If the platform is unsupported or Selenium Manager executable can't be found.
6573
"""
6674
compiled_path = Path(__file__).parent.joinpath("selenium-manager")
6775
exe = sysconfig.get_config_var("EXE")
@@ -71,9 +79,12 @@ def _get_binary() -> Path:
7179
path: Path | None = None
7280

7381
if (env_path := os.getenv("SE_MANAGER_PATH")) is not None:
74-
logger.debug("Selenium Manager set by env SE_MANAGER_PATH to: %s", env_path)
75-
path = Path(env_path)
76-
elif compiled_path.exists():
82+
logger.debug(f"Selenium Manager set by env SE_MANAGER_PATH to: {env_path}")
83+
path_candidate = Path(env_path)
84+
if not path_candidate.is_file():
85+
raise WebDriverException(f"SE_MANAGER_PATH does not point to a file: {env_path}")
86+
path = path_candidate
87+
elif compiled_path.is_file():
7788
path = compiled_path
7889
else:
7990
allowed = {
@@ -87,7 +98,7 @@ def _get_binary() -> Path:
8798

8899
arch = platform.machine() if sys.platform in ("linux", "freebsd", "openbsd") else "any"
89100
if sys.platform in ["freebsd", "openbsd"]:
90-
logger.warning("Selenium Manager binary may not be compatible with %s; verify settings", sys.platform)
101+
logger.warning(f"Selenium Manager binary may not be compatible with {sys.platform}; verify settings")
91102

92103
location = allowed.get((sys.platform, arch))
93104
if location is None:
@@ -98,7 +109,7 @@ def _get_binary() -> Path:
98109
if path is None or not path.is_file():
99110
raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}")
100111

101-
logger.debug("Selenium Manager binary found at: %s", path)
112+
logger.debug(f"Selenium Manager binary found at: {path}")
102113

103114
return path
104115

py/test/selenium/webdriver/common/selenium_manager_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_error_if_invalid_env_path(monkeypatch):
108108

109109
with pytest.raises(WebDriverException) as excinfo:
110110
SeleniumManager()._get_binary()
111-
assert f"Unable to obtain working Selenium Manager binary; {sm_path}" in str(excinfo.value)
111+
assert f"SE_MANAGER_PATH does not point to a file: {sm_path}" in str(excinfo.value)
112112

113113

114114
def test_run_successful():

0 commit comments

Comments
 (0)