Path: blob/trunk/py/selenium/webdriver/safari/service.py
4060 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617from collections.abc import Mapping, Sequence1819from selenium.webdriver.common import service202122class Service(service.Service):23"""Service class responsible for starting and stopping of `safaridriver`.2425This service is only supported on macOS.2627Args:28executable_path: (Optional) Install path of the safaridriver executable, defaults to `/usr/bin/safaridriver`.29port: (Optional) Port for the service to run on, defaults to 0 where the operating system will decide.30service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.31env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.32enable_logging: (Optional) Enable logging of the service. Logs can be located at33`~/Library/Logs/com.apple.WebDriver/`34driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.35"""3637def __init__(38self,39executable_path: str | None = None,40port: int = 0,41service_args: Sequence[str] | None = None,42env: Mapping[str, str] | None = None,43reuse_service=False,44enable_logging: bool = False,45driver_path_env_key: str | None = None,46**kwargs,47) -> None:48self._service_args = list(service_args or [])49driver_path_env_key = driver_path_env_key or "SE_SAFARIDRIVER"5051if enable_logging:52self._service_args.append("--diagnose")5354self.reuse_service = reuse_service55super().__init__(56executable_path=executable_path,57port=port,58env=env,59driver_path_env_key=driver_path_env_key,60**kwargs,61)6263def command_line_args(self) -> list[str]:64return ["-p", f"{self.port}"] + self._service_args6566@property67def service_url(self) -> str:68"""Gets the url of the SafariDriver Service."""69return f"http://localhost:{self.port}"7071@property72def reuse_service(self) -> bool:73return self._reuse_service7475@reuse_service.setter76def reuse_service(self, reuse: bool) -> None:77if not isinstance(reuse, bool):78raise TypeError("reuse must be a boolean")79self._reuse_service = reuse8081@property82def service_args(self) -> Sequence[str]:83"""Returns the sequence of service arguments."""84return self._service_args8586@service_args.setter87def service_args(self, value: Sequence[str]):88if isinstance(value, str) or not isinstance(value, Sequence):89raise TypeError("service_args must be a sequence")90self._service_args = list(value)919293