Path: blob/trunk/py/selenium/webdriver/chrome/service.py
4009 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 IO, Any1920from selenium.webdriver.chromium import service212223class Service(service.ChromiumService):24"""Service class responsible for starting and stopping the chromedriver executable.2526Args:27executable_path: Install path of the chromedriver executable, defaults28to `chromedriver`.29port: Port for the service to run on, defaults to 0 where the operating30system will decide.31service_args: (Optional) Sequence of args to be passed to the subprocess32when launching the executable.33log_output: (Optional) int representation of STDOUT/DEVNULL, any IO34instance or String path to file.35env: (Optional) Mapping of environment variables for the new process,36defaults to `os.environ`.37"""3839def __init__(40self,41executable_path: str | None = None,42port: int = 0,43service_args: Sequence[str] | None = None,44log_output: int | str | IO[Any] | None = None,45env: Mapping[str, str] | None = None,46**kwargs,47) -> None:48self._service_args = list(service_args or [])4950super().__init__(51executable_path=executable_path,52port=port,53service_args=service_args,54log_output=log_output,55env=env,56**kwargs,57)5859def command_line_args(self) -> list[str]:60return ["--enable-chrome-logs", f"--port={self.port}"] + self._service_args6162@property63def service_args(self) -> Sequence[str]:64"""Returns the sequence of service arguments."""65return self._service_args6667@service_args.setter68def service_args(self, value: Sequence[str]):69if isinstance(value, str) or not isinstance(value, Sequence):70raise TypeError("service_args must be a sequence")71self._service_args = list(value)727374