Skip to content

Commit 3b7295b

Browse files
committed
[py]: Additional types and docs for Service base class; fix firefox service init args
1 parent 7dbd3a3 commit 3b7295b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from urllib.error import URLError
3131

3232
from selenium.common.exceptions import WebDriverException
33+
from selenium.types import SubprocessStdAlias
3334
from selenium.webdriver.common import utils
3435

3536
log = logging.getLogger(__name__)
@@ -39,13 +40,23 @@
3940

4041

4142
class Service(ABC):
43+
"""The abstract base class for all service objects. Services typically launch a child program
44+
in a new process as an interim process to communicate with a browser.
45+
46+
:param executable: install path of the executable.
47+
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
48+
:param log_file: (Optional) file descriptor (pos int) or file object with a valid file descriptor.
49+
subprocess.PIPE & subprocess.DEVNULL are also valid values.
50+
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
51+
"""
52+
4253
def __init__(
4354
self,
4455
executable: str,
56+
start_error_message: str,
4557
port: int = 0,
46-
log_file=DEVNULL,
47-
env: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None,
48-
start_error_message: str = "",
58+
log_file: SubprocessStdAlias = DEVNULL,
59+
env: typing.Optional[typing.Mapping[typing.Any, typing.Any]] = None,
4960
) -> None:
5061
self.path = executable
5162
self.port = port or utils.free_port()
@@ -65,6 +76,7 @@ def service_url(self) -> str:
6576

6677
@abstractmethod
6778
def command_line_args(self) -> typing.List[str]:
79+
"""A List of program arguments (excluding the executable)."""
6880
raise NotImplementedError("This method needs to be implemented in a sub class")
6981

7082
def start(self) -> None:

py/selenium/webdriver/firefox/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
file = log_path or "geckodriver.log"
4848
log_file = open(file, "a+", encoding="utf-8")
4949
self.service_args = service_args or []
50-
super().__init__(executable_path, port=port, log_file=log_file, env=env)
50+
super().__init__(executable=executable_path, port=port, log_file=log_file, env=env)
5151

5252
# Set a port for CDP
5353
if "--connect-existing" not in self.service_args:

0 commit comments

Comments
 (0)