Skip to content

Commit

Permalink
Allow specifying browser binary path
Browse files Browse the repository at this point in the history
  • Loading branch information
sohang3112 committed Nov 21, 2023
1 parent 178a390 commit bf9982f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
6 changes: 4 additions & 2 deletions webdriver_manager/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def __init__(
chrome_type: str = ChromeType.GOOGLE,
download_manager: Optional[DownloadManager] = None,
cache_manager: Optional[DriverCacheManager] = None,
os_system_manager: Optional[OperationSystemManager] = None
os_system_manager: Optional[OperationSystemManager] = None,
binary_path: Optional[str] = None
):
super().__init__(
download_manager=download_manager,
cache_manager=cache_manager,
os_system_manager=os_system_manager
os_system_manager=os_system_manager,
binary_path=binary_path
)

self.driver = ChromeDriver(
Expand Down
16 changes: 10 additions & 6 deletions webdriver_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def __init__(
self,
download_manager=None,
cache_manager=None,
os_system_manager=None
os_system_manager=None,
binary_path=None
):
self._cache_manager = cache_manager
if not self._cache_manager:
Expand All @@ -22,6 +23,8 @@ def __init__(
self._os_system_manager = os_system_manager
if not self._os_system_manager:
self._os_system_manager = OperationSystemManager()

self.binary_path = binary_path
log("====== WebDriver manager ======")

@property
Expand All @@ -32,14 +35,15 @@ def install(self) -> str:
raise NotImplementedError("Please Implement this method")

def _get_driver_binary_path(self, driver):
binary_path = self._cache_manager.find_driver(driver)
if binary_path:
return binary_path
if self.binary_path is None:
self.binary_path = self._cache_manager.find_driver(driver)
if self.binary_path is not None:
return self.binary_path

os_type = self.get_os_type()
file = self._download_manager.download_file(driver.get_driver_download_url(os_type))
binary_path = self._cache_manager.save_file_to_cache(driver, file)
return binary_path
self.binary_path = self._cache_manager.save_file_to_cache(driver, file)
return self.binary_path

def get_os_type(self):
return self._os_system_manager.get_os_type()
6 changes: 4 additions & 2 deletions webdriver_manager/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ def __init__(
mozila_release_tag: str = "https://api.github.com/repos/mozilla/geckodriver/releases/tags/{0}",
download_manager: Optional[DownloadManager] = None,
cache_manager: Optional[DriverCacheManager] = None,
os_system_manager: Optional[OperationSystemManager] = None
os_system_manager: Optional[OperationSystemManager] = None,
binary_path: Optional[str] = None
):
super(GeckoDriverManager, self).__init__(
download_manager=download_manager,
cache_manager=cache_manager
cache_manager=cache_manager,
binary_path=binary_path
)

self.driver = GeckoDriver(
Expand Down
6 changes: 4 additions & 2 deletions webdriver_manager/microsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def __init__(
ie_release_tag: str = "https://api.github.com/repos/seleniumhq/selenium/releases/tags/selenium-{0}",
download_manager: Optional[DownloadManager] = None,
cache_manager: Optional[DriverCacheManager] = None,
os_system_manager: Optional[OperationSystemManager] = None
os_system_manager: Optional[OperationSystemManager] = None,
binary_path: Optional[str] = None
):
super().__init__(
download_manager=download_manager,
cache_manager=cache_manager
cache_manager=cache_manager,
binary_path=binary_path
)

self.driver = IEDriver(
Expand Down
6 changes: 4 additions & 2 deletions webdriver_manager/opera.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def __init__(
"operasoftware/operachromiumdriver/releases/tags/{0}",
download_manager: Optional[DownloadManager] = None,
cache_manager: Optional[DriverCacheManager] = None,
os_system_manager: Optional[OperationSystemManager] = None
os_system_manager: Optional[OperationSystemManager] = None,
binary_path: Optional[str] = None
):
super().__init__(
download_manager=download_manager,
cache_manager=cache_manager
cache_manager=cache_manager,
binary_path=binary_path
)

self.driver = OperaDriver(
Expand Down

0 comments on commit bf9982f

Please sign in to comment.