Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/webkitgtk/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
import warnings
20
from collections.abc import Mapping, Sequence
21
from typing import Optional
22
23
from selenium.webdriver.common import service
24
25
DEFAULT_EXECUTABLE_PATH: str = shutil.which("WebKitWebDriver")
26
27
28
class Service(service.Service):
29
"""A Service class that is responsible for the starting and stopping of
30
`WebKitWebDriver`.
31
32
:param executable_path: install path of the WebKitWebDriver executable, defaults to the first
33
`WebKitWebDriver` in `$PATH`.
34
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
35
:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
36
:param log_output: (Optional) File path for the file to be opened and passed as the subprocess
37
stdout/stderr handler.
38
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
39
"""
40
41
def __init__(
42
self,
43
executable_path: str = DEFAULT_EXECUTABLE_PATH,
44
port: int = 0,
45
log_path: Optional[str] = None,
46
log_output: Optional[str] = None,
47
service_args: Optional[Sequence[str]] = None,
48
env: Optional[Mapping[str, str]] = None,
49
**kwargs,
50
) -> None:
51
self._service_args = list(service_args or [])
52
if log_path is not None:
53
warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2)
54
log_path = open(log_path, "wb")
55
log_output = open(log_output, "wb") if log_output else None
56
57
super().__init__(
58
executable_path=executable_path,
59
port=port,
60
log_output=log_path or log_output,
61
env=env,
62
**kwargs,
63
)
64
65
def command_line_args(self) -> list[str]:
66
return ["-p", f"{self.port}"] + self._service_args
67
68
@property
69
def service_args(self) -> Sequence[str]:
70
return self._service_args
71
72
@service_args.setter
73
def service_args(self, value: Sequence[str]):
74
if isinstance(value, str) or not isinstance(value, Sequence):
75
raise TypeError("service_args must be a sequence")
76
self._service_args = list(value)
77
78