Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/selenium/webdriver/ie/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
from collections.abc import Sequence
19
from typing import Optional
20
21
from selenium.types import SubprocessStdAlias
22
from selenium.webdriver.common import service
23
24
25
class Service(service.Service):
26
"""Object that manages the starting and stopping of the IEDriver."""
27
28
def __init__(
29
self,
30
executable_path: Optional[str] = None,
31
port: int = 0,
32
host: Optional[str] = None,
33
service_args: Optional[Sequence[str]] = None,
34
log_level: Optional[str] = None,
35
log_output: Optional[SubprocessStdAlias] = None,
36
driver_path_env_key: Optional[str] = None,
37
**kwargs,
38
) -> None:
39
"""Creates a new instance of the Service.
40
41
:Args:
42
- executable_path : Path to the IEDriver
43
- port : Port the service is running on
44
- host : (Optional) IP address the service port is bound
45
- service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.
46
- log_level : (Optional) Level of logging of service, may be "FATAL", "ERROR", "WARN", "INFO", "DEBUG",
47
"TRACE". Default is "FATAL".
48
- log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.
49
Default is "stdout".
50
- driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.
51
"""
52
self._service_args = list(service_args or [])
53
driver_path_env_key = driver_path_env_key or "SE_IEDRIVER"
54
55
if host:
56
self._service_args.append(f"--host={host}")
57
if log_level:
58
self._service_args.append(f"--log-level={log_level}")
59
60
super().__init__(
61
executable_path=executable_path,
62
port=port,
63
log_output=log_output,
64
driver_path_env_key=driver_path_env_key,
65
**kwargs,
66
)
67
68
def command_line_args(self) -> list[str]:
69
return [f"--port={self.port}"] + self._service_args
70
71
@property
72
def service_args(self) -> Sequence[str]:
73
return self._service_args
74
75
@service_args.setter
76
def service_args(self, value: Sequence[str]):
77
if isinstance(value, str) or not isinstance(value, Sequence):
78
raise TypeError("service_args must be a sequence")
79
self._service_args = list(value)
80
81