| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import typing |
| 18 |
|
| 19 |
from selenium.webdriver.common import service |
| 20 |
|
| 21 |
DEFAULT_EXECUTABLE_PATH = "WebKitWebDriver" |
| 22 |
|
| 23 |
|
| 24 |
class Service(service.Service): |
| 25 |
"""A Service class that is responsible for the starting and stopping of |
| 26 |
`WPEWebDriver`. |
| 27 |
|
| 28 |
:param executable_path: install path of the WebKitWebDriver executable, defaults to `WebKitWebDriver`. |
| 29 |
:param port: Port for the service to run on, defaults to 0 where the operating system will decide. |
| 30 |
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable. |
| 31 |
:param log_path: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler. |
| 32 |
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. |
| 33 |
""" |
| 34 |
|
| 35 |
def __init__( |
| 36 |
self, |
| 37 |
executable_path: str = DEFAULT_EXECUTABLE_PATH, |
| 38 |
port: int = 0, |
| 39 |
log_path: typing.Optional[str] = None, |
| 40 |
service_args: typing.Optional[typing.List[str]] = None, |
| 41 |
env: typing.Optional[typing.Mapping[str, str]] = None, |
| 42 |
**kwargs, |
| 43 |
): |
| 44 |
self.service_args = service_args or [] |
| 45 |
log_file = open(log_path, "wb") if log_path else None |
| 46 |
super().__init__( |
| 47 |
executable_path=executable_path, |
| 48 |
port=port, |
| 49 |
log_file=log_file, |
| 50 |
env=env, |
| 51 |
**kwargs, |
| 52 |
) |
| 53 |
|
| 54 |
def command_line_args(self) -> typing.List[str]: |
| 55 |
return ["-p", f"{self.port}"] + self.service_args |