Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/wpewebkit/service.py
1864 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 Optional
21
22
from selenium.webdriver.common import service
23
24
DEFAULT_EXECUTABLE_PATH = shutil.which("WPEWebDriver")
25
26
27
class Service(service.Service):
28
"""A Service class that is responsible for the starting and stopping of
29
`WPEWebDriver`.
30
31
:param executable_path: install path of the WPEWebDriver executable, defaults to the first
32
`WPEWebDriver` in `$PATH`.
33
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
34
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
35
:param log_output: (Optional) File path for the file to be opened and passed as the subprocess
36
stdout/stderr handler.
37
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
38
"""
39
40
def __init__(
41
self,
42
executable_path: str = DEFAULT_EXECUTABLE_PATH,
43
port: int = 0,
44
log_output: Optional[str] = None,
45
service_args: Optional[Sequence[str]] = None,
46
env: Optional[Mapping[str, str]] = None,
47
**kwargs,
48
):
49
self._service_args = list(service_args or [])
50
51
super().__init__(
52
executable_path=executable_path,
53
port=port,
54
log_output=log_output,
55
env=env,
56
**kwargs,
57
)
58
59
def command_line_args(self) -> list[str]:
60
return ["-p", f"{self.port}"] + self._service_args
61
62
@property
63
def service_args(self) -> Sequence[str]:
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