From 7c7e2ecba28d0ac7c95658b315970fd1b6ed95f3 Mon Sep 17 00:00:00 2001 From: symonk Date: Wed, 5 Oct 2022 00:31:59 +0100 Subject: [PATCH] [py]: docs, type hints and clean up for `ChromiumService` --- py/selenium/webdriver/chrome/service.py | 4 +-- py/selenium/webdriver/chromium/service.py | 42 +++++++++++++---------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/py/selenium/webdriver/chrome/service.py b/py/selenium/webdriver/chrome/service.py index 9ecf0acae09c8..3eb57e49b7bb2 100644 --- a/py/selenium/webdriver/chrome/service.py +++ b/py/selenium/webdriver/chrome/service.py @@ -27,8 +27,8 @@ class Service(service.ChromiumService): :param executable_path: install path of the chromedriver executable, defaults to `chromedriver`. :param port: Port for the service to run on, defaults to 0 where the operating system will decide. - :param service_args: (Optional) Sequence of args/flags to be passed to the `chromedriver` subprocess. - :param log_path: (Optional) String to be passed to the executable as `--log-path` + :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param log_path: (Optional) String to be passed to the executable as `--log-path`. :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. """ diff --git a/py/selenium/webdriver/chromium/service.py b/py/selenium/webdriver/chromium/service.py index 0c55afdf69f4e..180817369457c 100644 --- a/py/selenium/webdriver/chromium/service.py +++ b/py/selenium/webdriver/chromium/service.py @@ -15,42 +15,46 @@ # specific language governing permissions and limitations # under the License. import typing -from typing import List from selenium.webdriver.common import service class ChromiumService(service.Service): - """ - Object that manages the starting and stopping the WebDriver instance of the ChromiumDriver + """A Service class that is responsible for the starting and stopping + the WebDriver instance of the ChromiumDriver. + + :param executable_path: install path of the executable. + :param port: Port for the service to run on, defaults to 0 where the operating system will decide. + :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. + :param log_path: (Optional) String to be passed to the executable as `--log-path` + :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. + :param start_error_message: (Optional) Error message that forms part of the error when problems occur + launching the subprocess. """ def __init__( self, executable_path: str, port: int = 0, - service_args: typing.Optional[List[str]] = None, + service_args: typing.Optional[typing.Sequence[str]] = None, log_path: typing.Optional[str] = None, - env: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None, - start_error_message: str = "", + env: typing.Optional[typing.Mapping[str, str]] = None, + start_error_message: typing.Optional[str] = None, ): - """ - Creates a new instance of the Service - - :Args: - - executable_path : Path to the WebDriver executable - - port : Port the service is running on - - service_args : List of args to pass to the WebDriver service - - log_path : Path for the WebDriver service to log to""" - self.service_args = service_args or [] if log_path: - self.service_args.append("--log-path=%s" % log_path) + self.service_args.append(f"--log-path={log_path}") if not start_error_message: - raise AttributeError("start_error_message should not be empty") + # Todo: Make this a required arg in future. + raise TypeError("`start_error_message` must be provided.") - super().__init__(executable_path, port=port, env=env, start_error_message=start_error_message) + super().__init__( + executable=executable_path, + port=port, + env=env, + start_error_message=start_error_message, + ) - def command_line_args(self) -> List[str]: + def command_line_args(self) -> typing.List[str]: return ["--port=%d" % self.port] + self.service_args