Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/chrome/service.py
4009 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
from collections.abc import Mapping, Sequence
19
from typing import IO, Any
20
21
from selenium.webdriver.chromium import service
22
23
24
class Service(service.ChromiumService):
25
"""Service class responsible for starting and stopping the chromedriver executable.
26
27
Args:
28
executable_path: Install path of the chromedriver executable, defaults
29
to `chromedriver`.
30
port: Port for the service to run on, defaults to 0 where the operating
31
system will decide.
32
service_args: (Optional) Sequence of args to be passed to the subprocess
33
when launching the executable.
34
log_output: (Optional) int representation of STDOUT/DEVNULL, any IO
35
instance or String path to file.
36
env: (Optional) Mapping of environment variables for the new process,
37
defaults to `os.environ`.
38
"""
39
40
def __init__(
41
self,
42
executable_path: str | None = None,
43
port: int = 0,
44
service_args: Sequence[str] | None = None,
45
log_output: int | str | IO[Any] | None = None,
46
env: Mapping[str, str] | None = None,
47
**kwargs,
48
) -> None:
49
self._service_args = list(service_args or [])
50
51
super().__init__(
52
executable_path=executable_path,
53
port=port,
54
service_args=service_args,
55
log_output=log_output,
56
env=env,
57
**kwargs,
58
)
59
60
def command_line_args(self) -> list[str]:
61
return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args
62
63
@property
64
def service_args(self) -> Sequence[str]:
65
"""Returns the sequence of service arguments."""
66
return self._service_args
67
68
@service_args.setter
69
def service_args(self, value: Sequence[str]):
70
if isinstance(value, str) or not isinstance(value, Sequence):
71
raise TypeError("service_args must be a sequence")
72
self._service_args = list(value)
73
74