Path: blob/trunk/py/selenium/webdriver/safari/service.py
1864 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, Sequence18from typing import Optional1920from selenium.webdriver.common import service212223class Service(service.Service):24"""A Service class that is responsible for the starting and stopping of25`safaridriver` This is only supported on MAC OSX.2627: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) Sequence 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:param enable_logging: (Optional) Enable logging of the service. Logs can be located at32`~/Library/Logs/com.apple.WebDriver/`33:param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.34"""3536def __init__(37self,38executable_path: Optional[str] = None,39port: int = 0,40service_args: Optional[Sequence[str]] = None,41env: Optional[Mapping[str, str]] = None,42reuse_service=False,43enable_logging: bool = False,44driver_path_env_key: Optional[str] = None,45**kwargs,46) -> None:47self._service_args = list(service_args or [])48driver_path_env_key = driver_path_env_key or "SE_SAFARIDRIVER"4950if enable_logging:51self._service_args.append("--diagnose")5253self.reuse_service = reuse_service54super().__init__(55executable_path=executable_path,56port=port,57env=env,58driver_path_env_key=driver_path_env_key,59**kwargs,60)6162def command_line_args(self) -> list[str]:63return ["-p", f"{self.port}"] + self._service_args6465@property66def service_url(self) -> str:67"""Gets the url of the SafariDriver Service."""68return f"http://localhost:{self.port}"6970@property71def reuse_service(self) -> bool:72return self._reuse_service7374@reuse_service.setter75def reuse_service(self, reuse: bool) -> None:76if not isinstance(reuse, bool):77raise TypeError("reuse must be a boolean")78self._reuse_service = reuse7980@property81def service_args(self) -> Sequence[str]:82return self._service_args8384@service_args.setter85def service_args(self, value: Sequence[str]):86if isinstance(value, str) or not isinstance(value, Sequence):87raise TypeError("service_args must be a sequence")88self._service_args = list(value)899091