|
14 | 14 | # KIND, either express or implied. See the License for the
|
15 | 15 | # specific language governing permissions and limitations
|
16 | 16 | # under the License.
|
17 |
| - |
| 17 | +import typing |
18 | 18 | from typing import List
|
19 | 19 |
|
20 | 20 | from selenium.webdriver.common import service
|
|
24 | 24 |
|
25 | 25 |
|
26 | 26 | class Service(service.Service):
|
27 |
| - """Object that manages the starting and stopping of the |
28 |
| - GeckoDriver.""" |
| 27 | + """A Service class that is responsible for the starting and stopping |
| 28 | + of `geckodriver`. |
| 29 | +
|
| 30 | + :param executable_path: install path of the geckodriver executable, defaults to `geckodriver`. |
| 31 | + :param port: Port for the service to run on, defaults to 0 where the operating system will decide. |
| 32 | + :param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. |
| 33 | + :param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler, |
| 34 | + defaults to `geckodriver.log`. |
| 35 | + :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. |
| 36 | + """ |
29 | 37 |
|
30 | 38 | def __init__(
|
31 | 39 | self,
|
32 | 40 | executable_path: str = DEFAULT_EXECUTABLE_PATH,
|
33 | 41 | port: int = 0,
|
34 |
| - service_args: List[str] = None, |
35 |
| - log_path: str = "geckodriver.log", |
36 |
| - env: dict = None, |
| 42 | + service_args: typing.Optional[typing.List[str]] = None, |
| 43 | + log_path: typing.Optional[str] = None, |
| 44 | + env: typing.Optional[typing.Mapping[str, str]] = None, |
37 | 45 | ):
|
38 |
| - """Creates a new instance of the GeckoDriver remote service proxy. |
39 |
| -
|
40 |
| - GeckoDriver provides a HTTP interface speaking the W3C WebDriver |
41 |
| - protocol to Marionette. |
42 |
| -
|
43 |
| - :param executable_path: Path to the GeckoDriver binary. |
44 |
| - :param port: Run the remote service on a specified port. |
45 |
| - Defaults to 0, which binds to a random open port of the |
46 |
| - system's choosing. |
47 |
| - :param service_args: Optional list of arguments to pass to the |
48 |
| - GeckoDriver binary. |
49 |
| - :param log_path: Optional path for the GeckoDriver to log to. |
50 |
| - Defaults to _geckodriver.log_ in the current working directory. |
51 |
| - :param env: Optional dictionary of output variables to expose |
52 |
| - in the services' environment. |
53 |
| -
|
54 |
| - """ |
55 |
| - log_file = open(log_path, "a+", encoding="utf-8") if log_path else None |
56 |
| - |
57 |
| - super().__init__(executable_path, port=port, log_file=log_file, env=env) |
| 46 | + # Todo: This is vastly inconsistent, requires a follow up to standardise. |
| 47 | + file = log_path or "geckodriver.log" |
| 48 | + log_file = open(file, "a+", encoding="utf-8") |
58 | 49 | self.service_args = service_args or []
|
| 50 | + super().__init__(executable_path, port=port, log_file=log_file, env=env) |
59 | 51 |
|
60 | 52 | # Set a port for CDP
|
61 | 53 | if "--connect-existing" not in self.service_args:
|
62 | 54 | self.service_args.append("--websocket-port")
|
63 | 55 | self.service_args.append(f"{utils.free_port()}")
|
64 | 56 |
|
65 |
| - # Set the webdriver port |
66 |
| - self.service_args.append("--port") |
67 |
| - self.service_args.append(f"{self.port}") |
68 |
| - |
69 | 57 | def command_line_args(self) -> List[str]:
|
70 |
| - return self.service_args |
71 |
| - |
72 |
| - def send_remote_shutdown_command(self): |
73 |
| - pass |
| 58 | + return ["--port", f"{self.port}"] + self.service_args |
0 commit comments