Path: blob/trunk/py/selenium/webdriver/chromium/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 io import IOBase19from typing import Optional2021from selenium.types import SubprocessStdAlias22from selenium.webdriver.common import service232425class ChromiumService(service.Service):26"""A Service class that is responsible for the starting and stopping the27WebDriver instance of the ChromiumDriver.2829:param executable_path: install path of the executable.30:param port: Port for the service to run on, defaults to 0 where the operating system will decide.31:param service_args: (Optional) Sequence of args to be passed to the subprocess when launching the executable.32:param log_output: (Optional) int representation of STDOUT/DEVNULL, any IO instance or String path to file.33:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.34:param driver_path_env_key: (Optional) Environment variable to use to get the path to the driver executable.35"""3637def __init__(38self,39executable_path: Optional[str] = None,40port: int = 0,41service_args: Optional[Sequence[str]] = None,42log_output: Optional[SubprocessStdAlias] = None,43env: Optional[Mapping[str, str]] = None,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_CHROMEDRIVER"4950if isinstance(log_output, str):51self._service_args.append(f"--log-path={log_output}")52self.log_output: Optional[IOBase] = None53elif isinstance(log_output, IOBase):54self.log_output = log_output55else:56self.log_output = log_output5758super().__init__(59executable_path=executable_path,60port=port,61env=env,62log_output=self.log_output,63driver_path_env_key=driver_path_env_key,64**kwargs,65)6667def command_line_args(self) -> list[str]:68return [f"--port={self.port}"] + self._service_args6970@property71def service_args(self) -> Sequence[str]:72return self._service_args7374@service_args.setter75def service_args(self, value: Sequence[str]):76if isinstance(value, str) or not isinstance(value, Sequence):77raise TypeError("service_args must be a sequence")78self._service_args = list(value)798081