Skip to content

Commit 7c7e2ec

Browse files
committed
[py]: docs, type hints and clean up for ChromiumService
1 parent 3a788a3 commit 7c7e2ec

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

py/selenium/webdriver/chrome/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class Service(service.ChromiumService):
2727
2828
:param executable_path: install path of the chromedriver executable, defaults to `chromedriver`.
2929
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
30-
:param service_args: (Optional) Sequence of args/flags to be passed to the `chromedriver` subprocess.
31-
:param log_path: (Optional) String to be passed to the executable as `--log-path`
30+
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
31+
:param log_path: (Optional) String to be passed to the executable as `--log-path`.
3232
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
3333
"""
3434

py/selenium/webdriver/chromium/service.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,46 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import typing
18-
from typing import List
1918

2019
from selenium.webdriver.common import service
2120

2221

2322
class ChromiumService(service.Service):
24-
"""
25-
Object that manages the starting and stopping the WebDriver instance of the ChromiumDriver
23+
"""A Service class that is responsible for the starting and stopping
24+
the WebDriver instance of the ChromiumDriver.
25+
26+
:param executable_path: install path of the executable.
27+
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
28+
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
29+
:param log_path: (Optional) String to be passed to the executable as `--log-path`
30+
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
31+
:param start_error_message: (Optional) Error message that forms part of the error when problems occur
32+
launching the subprocess.
2633
"""
2734

2835
def __init__(
2936
self,
3037
executable_path: str,
3138
port: int = 0,
32-
service_args: typing.Optional[List[str]] = None,
39+
service_args: typing.Optional[typing.Sequence[str]] = None,
3340
log_path: typing.Optional[str] = None,
34-
env: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None,
35-
start_error_message: str = "",
41+
env: typing.Optional[typing.Mapping[str, str]] = None,
42+
start_error_message: typing.Optional[str] = None,
3643
):
37-
"""
38-
Creates a new instance of the Service
39-
40-
:Args:
41-
- executable_path : Path to the WebDriver executable
42-
- port : Port the service is running on
43-
- service_args : List of args to pass to the WebDriver service
44-
- log_path : Path for the WebDriver service to log to"""
45-
4644
self.service_args = service_args or []
4745
if log_path:
48-
self.service_args.append("--log-path=%s" % log_path)
46+
self.service_args.append(f"--log-path={log_path}")
4947

5048
if not start_error_message:
51-
raise AttributeError("start_error_message should not be empty")
49+
# Todo: Make this a required arg in future.
50+
raise TypeError("`start_error_message` must be provided.")
5251

53-
super().__init__(executable_path, port=port, env=env, start_error_message=start_error_message)
52+
super().__init__(
53+
executable=executable_path,
54+
port=port,
55+
env=env,
56+
start_error_message=start_error_message,
57+
)
5458

55-
def command_line_args(self) -> List[str]:
59+
def command_line_args(self) -> typing.List[str]:
5660
return ["--port=%d" % self.port] + self.service_args

0 commit comments

Comments
 (0)