diff --git a/py/selenium/webdriver/common/virtual_authenticator.py b/py/selenium/webdriver/common/virtual_authenticator.py index c0ae055e1e068..74c0330d7d3ff 100644 --- a/py/selenium/webdriver/common/virtual_authenticator.py +++ b/py/selenium/webdriver/common/virtual_authenticator.py @@ -112,7 +112,7 @@ def is_resident_credential(self) -> bool: return self._is_resident_credential @property - def rp_id(self) -> str: + def rp_id(self) -> Optional[str]: return self._rp_id @property diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index ec514fc0fc433..b70b5e4204550 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -18,11 +18,11 @@ import shutil import warnings from collections.abc import Mapping, Sequence -from typing import Optional +from typing import IO, Optional from selenium.webdriver.common import service -DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver") +DEFAULT_EXECUTABLE_PATH: Optional[str] = shutil.which("WebKitWebDriver") class Service(service.Service): @@ -44,7 +44,7 @@ class Service(service.Service): def __init__( self, - executable_path: str = DEFAULT_EXECUTABLE_PATH, + executable_path: Optional[str] = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_path: Optional[str] = None, log_output: Optional[str] = None, @@ -53,18 +53,30 @@ def __init__( **kwargs, ) -> None: self._service_args = list(service_args or []) - if log_path is not None: - warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2) - log_path = open(log_path, "wb") - log_output = open(log_output, "wb") if log_output else None - super().__init__( - executable_path=executable_path, - port=port, - log_output=log_path or log_output, - env=env, - **kwargs, - ) + log_file: Optional[IO[bytes]] = None + + try: + if log_output is not None: + log_file = open(log_output, "wb") + elif log_path is not None: + warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2) + log_file = open(log_path, "wb") + + super().__init__( + executable_path=executable_path, + port=port, + log_output=log_file, + env=env, + **kwargs, + ) + except Exception: + if log_file is not None: + try: + log_file.close() + except Exception: + pass + raise def command_line_args(self) -> list[str]: return ["-p", f"{self.port}"] + self._service_args diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index 928eca35756f7..70b09c01f23e9 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -43,7 +43,7 @@ class Service(service.Service): def __init__( self, - executable_path: str = DEFAULT_EXECUTABLE_PATH, + executable_path: Optional[str] = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_output: Optional[str] = None, service_args: Optional[Sequence[str]] = None,