Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/wpewebkit/service.py
3989 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import shutil
19
from collections.abc import Mapping, Sequence
20
from typing import IO, Any
21
22
from selenium.webdriver.common import service
23
24
DEFAULT_EXECUTABLE_PATH: str | None = shutil.which("WPEWebDriver")
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)
71
72