From 4a759a8cfb2c5a34a036080c621e8b4ed19bf20e Mon Sep 17 00:00:00 2001 From: symonk Date: Wed, 5 Oct 2022 17:30:26 +0100 Subject: [PATCH] [py]: Types and docs for `wpiwebkit.service` and additional args for consistency --- py/selenium/webdriver/webkitgtk/service.py | 3 +- py/selenium/webdriver/wpewebkit/service.py | 35 +++++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/py/selenium/webdriver/webkitgtk/service.py b/py/selenium/webdriver/webkitgtk/service.py index 3da12826c3bae..f8c48d3c1cb4b 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 typing from selenium.webdriver.common import service @@ -37,5 +38,5 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH, port=0, log_p log_file = open(log_path, "wb") if log_path else None super().__init__(executable_path, port, log_file) - def command_line_args(self): + def command_line_args(self) -> typing.List[str]: return ["-p", f"{self.port}"] diff --git a/py/selenium/webdriver/wpewebkit/service.py b/py/selenium/webdriver/wpewebkit/service.py index e676595885e70..feb05b9578620 100644 --- a/py/selenium/webdriver/wpewebkit/service.py +++ b/py/selenium/webdriver/wpewebkit/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 typing from selenium.webdriver.common import service @@ -21,21 +22,27 @@ class Service(service.Service): - """ - Object that manages the starting and stopping of the WPEWebKitDriver - """ + """A Service class that is responsible for the starting and stopping + of `WPEWebDriver`. - def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH, port=0, log_path=None): - """ - Creates a new instance of the Service + :param executable_path: install path of the WPEWebDriver executable, defaults to `WPEWebDriver`. + :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`. + """ - :Args: - - executable_path : Path to the WPEWebKitDriver - - port : Port the service is running on - - log_path : Path for the WPEWebKitDriver service to log to - """ + def __init__( + self, + executable_path: str = DEFAULT_EXECUTABLE_PATH, + port: int = 0, + log_path: typing.Optional[str] = None, + service_args: typing.Optional[typing.Sequence[str]] = None, + env: typing.Optional[typing.Mapping[str, str]] = None, + ): + self.service_args = service_args or [] log_file = open(log_path, "wb") if log_path else None - super().__init__(executable_path, port, log_file) + super().__init__(executable=executable_path, port=port, log_file=log_file, env=env) - def command_line_args(self): - return ["-p", f"{self.port}"] + def command_line_args(self) -> typing.List[str]: + return ["-p", f"{self.port}"] + self.service_args