|
15 | 15 | # specific language governing permissions and limitations
|
16 | 16 | # under the License.
|
17 | 17 | import typing
|
18 |
| -from typing import List |
19 | 18 |
|
20 | 19 | from selenium.webdriver.common import service
|
21 | 20 |
|
22 | 21 |
|
23 | 22 | 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. |
26 | 33 | """
|
27 | 34 |
|
28 | 35 | def __init__(
|
29 | 36 | self,
|
30 | 37 | executable_path: str,
|
31 | 38 | port: int = 0,
|
32 |
| - service_args: typing.Optional[List[str]] = None, |
| 39 | + service_args: typing.Optional[typing.Sequence[str]] = None, |
33 | 40 | 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, |
36 | 43 | ):
|
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 |
| - |
46 | 44 | self.service_args = service_args or []
|
47 | 45 | if log_path:
|
48 |
| - self.service_args.append("--log-path=%s" % log_path) |
| 46 | + self.service_args.append(f"--log-path={log_path}") |
49 | 47 |
|
50 | 48 | 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.") |
52 | 51 |
|
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 | + ) |
54 | 58 |
|
55 |
| - def command_line_args(self) -> List[str]: |
| 59 | + def command_line_args(self) -> typing.List[str]: |
56 | 60 | return ["--port=%d" % self.port] + self.service_args
|
0 commit comments