diff --git a/appium/webdriver/appium_service.py b/appium/webdriver/appium_service.py index fe34d869..787742b1 100644 --- a/appium/webdriver/appium_service.py +++ b/appium/webdriver/appium_service.py @@ -14,6 +14,7 @@ import os import re +import shutil import subprocess as sp import sys import time @@ -225,21 +226,7 @@ def is_service_listening(url: str, timeout: float = 5, custom_validator: Callabl def find_executable(executable: str) -> str | None: - path = os.environ['PATH'] - paths = path.split(os.pathsep) - _, ext = os.path.splitext(executable) - if sys.platform == 'win32' and not ext: - executable = executable + '.exe' - - if os.path.isfile(executable): - return executable - - for p in paths: - full_path = os.path.join(p, executable) - if os.path.isfile(full_path): - return full_path - - return None + return shutil.which(executable) def get_node() -> str: diff --git a/test/unit/webdriver/appium_service_test.py b/test/unit/webdriver/appium_service_test.py index d0826c8f..1a3c2be0 100644 --- a/test/unit/webdriver/appium_service_test.py +++ b/test/unit/webdriver/appium_service_test.py @@ -24,6 +24,14 @@ class TestAppiumService: def test_get_instance(self): assert AppiumService() + def test_find_executable_found(self, monkeypatch): + monkeypatch.setattr(appium_service.shutil, 'which', lambda cmd: f'/usr/bin/{cmd}') + assert appium_service.find_executable('node') == '/usr/bin/node' + + def test_find_executable_not_found(self, monkeypatch): + monkeypatch.setattr(appium_service.shutil, 'which', lambda cmd: None) + assert appium_service.find_executable('non_existent_exe') is None + @pytest.mark.parametrize( ('status', 'expected_result', 'expected_elapsed', 'expected_requests'), [(200, True, 0.0, 1), (503, False, 5.0, 10)],