Debian Codegraph @

selenium/webdriver/safari/service.py

raw symbols SCIP
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 typing
19
20 from selenium.webdriver.common import service
21
22
23 class Service(service.Service):
24 """A Service class that is responsible for the starting and stopping of
25 `safaridriver` This is only supported on MAC OSX.
26
27 :param executable_path: install path of the safaridriver executable, defaults to `/usr/bin/safaridriver`.
28 :param port: Port for the service to run on, defaults to 0 where the operating system will decide.
29 :param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
30 :param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
31 """
32
33 def __init__(
34 self,
35 executable_path: str = None,
36 port: int = 0,
37 service_args: typing.Optional[typing.List[str]] = None,
38 env: typing.Optional[typing.Mapping[str, str]] = None,
39 reuse_service=False,
40 **kwargs,
41 ) -> None:
42 self.service_args = service_args or []
43
44 self.reuse_service = reuse_service
45 super().__init__(
46 executable_path=executable_path,
47 port=port,
48 env=env,
49 **kwargs,
50 )
51
52 def command_line_args(self) -> typing.List[str]:
53 return ["-p", f"{self.port}"] + self.service_args
54
55 @property
56 def service_url(self) -> str:
57 """Gets the url of the SafariDriver Service."""
58 return f"http://localhost:{self.port}"
59
60 @property
61 def reuse_service(self) -> bool:
62 return self._reuse_service
63
64 @reuse_service.setter
65 def reuse_service(self, reuse: bool) -> None:
66 if not isinstance(reuse, bool):
67 raise TypeError("reuse must be a boolean")
68 self._reuse_service = reuse