Service class that is responsible for the starting and stopping of `WPEWebDriver`. Args: executable_path: (Optional) Install path of the WPEWebDriver executable, defaults to the first `WPEWebDriver` in `$PATH`. port: (Optional) Port for the service to run on, default
| 25 | |
| 26 | |
| 27 | class Service(service.Service): |
| 28 | """Service class that is responsible for the starting and stopping of `WPEWebDriver`. |
| 29 | |
| 30 | Args: |
| 31 | executable_path: (Optional) Install path of the WPEWebDriver executable, defaults to the first `WPEWebDriver` |
| 32 | in `$PATH`. |
| 33 | port: (Optional) Port for the service to run on, defaults to 0 where the operating system will decide. |
| 34 | service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable. |
| 35 | log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file. |
| 36 | env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`. |
| 37 | """ |
| 38 | |
| 39 | def __init__( |
| 40 | self, |
| 41 | executable_path: str | None = DEFAULT_EXECUTABLE_PATH, |
| 42 | port: int = 0, |
| 43 | log_output: int | str | IO[Any] | None = None, |
| 44 | service_args: Sequence[str] | None = None, |
| 45 | env: Mapping[str, str] | None = None, |
| 46 | **kwargs, |
| 47 | ): |
| 48 | self._service_args = list(service_args or []) |
| 49 | |
| 50 | super().__init__( |
| 51 | executable_path=executable_path, |
| 52 | port=port, |
| 53 | log_output=log_output, |
| 54 | env=env, |
| 55 | **kwargs, |
| 56 | ) |
| 57 | |
| 58 | def command_line_args(self) -> list[str]: |
| 59 | return ["-p", f"{self.port}"] + self._service_args |
| 60 | |
| 61 | @property |
| 62 | def service_args(self) -> Sequence[str]: |
| 63 | """Returns the sequence of service arguments.""" |
| 64 | return self._service_args |
| 65 | |
| 66 | @service_args.setter |
| 67 | def service_args(self, value: Sequence[str]): |
| 68 | if isinstance(value, str) or not isinstance(value, Sequence): |
| 69 | raise TypeError("service_args must be a sequence") |
| 70 | self._service_args = list(value) |