diff --git a/py/selenium/webdriver/chrome/service.py b/py/selenium/webdriver/chrome/service.py index 40f94841b2304..3e06297710079 100644 --- a/py/selenium/webdriver/chrome/service.py +++ b/py/selenium/webdriver/chrome/service.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. - from typing import List from typing import Mapping from typing import Optional diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index f6c71e3ba719a..c6489aaf781f7 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + from io import IOBase from typing import List from typing import Mapping @@ -44,7 +45,7 @@ def __init__( driver_path_env_key: str = None, **kwargs, ) -> None: - self.service_args = service_args or [] + self._service_args = service_args or [] driver_path_env_key = driver_path_env_key or "SE_CHROMEDRIVER" if isinstance(log_output, str): @@ -64,5 +65,15 @@ def __init__( **kwargs, ) + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value + def command_line_args(self) -> List[str]: - return [f"--port={self.port}"] + self.service_args + return [f"--port={self.port}"] + self._service_args diff --git a/py/selenium/webdriver/edge/service.py b/py/selenium/webdriver/edge/service.py index ea49d8c5ca3a0..95532048ead98 100644 --- a/py/selenium/webdriver/edge/service.py +++ b/py/selenium/webdriver/edge/service.py @@ -44,15 +44,25 @@ def __init__( driver_path_env_key: str = None, **kwargs, ) -> None: - self.service_args = service_args or [] + self._service_args = service_args or [] driver_path_env_key = driver_path_env_key or "SE_EDGEDRIVER" super().__init__( executable_path=executable_path, port=port, - service_args=service_args, + service_args=self.service_args, log_output=log_output, env=env, driver_path_env_key=driver_path_env_key, **kwargs, ) + + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value diff --git a/py/selenium/webdriver/firefox/service.py b/py/selenium/webdriver/firefox/service.py index 59c8c18058b3b..8c2635424871d 100644 --- a/py/selenium/webdriver/firefox/service.py +++ b/py/selenium/webdriver/firefox/service.py @@ -44,7 +44,7 @@ def __init__( driver_path_env_key: str = None, **kwargs, ) -> None: - self.service_args = service_args or [] + self._service_args = service_args or [] driver_path_env_key = driver_path_env_key or "SE_GECKODRIVER" super().__init__( @@ -57,9 +57,19 @@ def __init__( ) # Set a port for CDP - if "--connect-existing" not in self.service_args: - self.service_args.append("--websocket-port") - self.service_args.append(f"{utils.free_port()}") + if "--connect-existing" not in self._service_args: + self._service_args.append("--websocket-port") + self._service_args.append(f"{utils.free_port()}") def command_line_args(self) -> List[str]: - return ["--port", f"{self.port}"] + self.service_args + return ["--port", f"{self.port}"] + self._service_args + + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value diff --git a/py/selenium/webdriver/ie/service.py b/py/selenium/webdriver/ie/service.py index bd9c116ced459..400ccd7f9bec6 100644 --- a/py/selenium/webdriver/ie/service.py +++ b/py/selenium/webdriver/ie/service.py @@ -46,13 +46,14 @@ def __init__( - log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. Default is "stdout". """ - self.service_args = service_args or [] + + self._service_args = service_args or [] driver_path_env_key = driver_path_env_key or "SE_IEDRIVER" if host: - self.service_args.append(f"--host={host}") + self._service_args.append(f"--host={host}") if log_level: - self.service_args.append(f"--log-level={log_level}") + self._service_args.append(f"--log-level={log_level}") super().__init__( executable_path=executable_path, @@ -63,4 +64,14 @@ def __init__( ) def command_line_args(self) -> List[str]: - return [f"--port={self.port}"] + self.service_args + return [f"--port={self.port}"] + self._service_args + + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value diff --git a/py/selenium/webdriver/safari/service.py b/py/selenium/webdriver/safari/service.py index c20e2ec85df05..53f79eb651f51 100644 --- a/py/selenium/webdriver/safari/service.py +++ b/py/selenium/webdriver/safari/service.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. - from typing import List from typing import Mapping from typing import Optional @@ -45,11 +44,11 @@ def __init__( driver_path_env_key: str = None, **kwargs, ) -> None: - self.service_args = service_args or [] + self._service_args = service_args or [] driver_path_env_key = driver_path_env_key or "SE_SAFARIDRIVER" if enable_logging: - self.service_args.append("--diagnose") + self._service_args.append("--diagnose") self.reuse_service = reuse_service super().__init__( @@ -61,7 +60,7 @@ def __init__( ) def command_line_args(self) -> List[str]: - return ["-p", f"{self.port}"] + self.service_args + return ["-p", f"{self.port}"] + self._service_args @property def service_url(self) -> str: @@ -77,3 +76,13 @@ def reuse_service(self, reuse: bool) -> None: if not isinstance(reuse, bool): raise TypeError("reuse must be a boolean") self._reuse_service = reuse + + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index 7414556370bd0..0eba3d7c4d89d 100644 --- a/py/selenium/webdriver/webkitgtk/service.py +++ b/py/selenium/webdriver/webkitgtk/service.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + import warnings from typing import List from typing import Mapping @@ -59,4 +60,14 @@ def __init__( ) def command_line_args(self) -> List[str]: - return ["-p", f"{self.port}"] + self.service_args + return ["-p", f"{self.port}"] + self._service_args + + @property + def service_args(self) -> List[str]: + return self._service_args + + @service_args.setter + def service_args(self, value: List[str]): + if not isinstance(value, List): + raise TypeError("service args must be a List of strings") + self._service_args = value diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index 8f392cf522706..9f4ec7488dfd2 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/service.py @@ -18,6 +18,7 @@ from typing import List from typing import Mapping from typing import Optional +from typing import Sequence from selenium.webdriver.common import service @@ -40,11 +41,11 @@ def __init__( executable_path: str = DEFAULT_EXECUTABLE_PATH, port: int = 0, log_output: Optional[str] = None, - service_args: Optional[List[str]] = None, + service_args: Optional[Sequence[str]] = None, env: Optional[Mapping[str, str]] = None, **kwargs, ): - self.service_args = service_args or [] + self._service_args = service_args or [] super().__init__( executable_path=executable_path, port=port, @@ -54,4 +55,14 @@ def __init__( ) def command_line_args(self) -> List[str]: - return ["-p", f"{self.port}"] + self.service_args + return ["-p", f"{self.port}"] + self._service_args + + @property + def service_args(self): + return self._service_args + + @service_args.setter + def service_args(self, value): + if not isinstance(value, Sequence): + raise TypeError("service args must be a sequence") + self._service_args = value