Path: blob/trunk/rb/lib/selenium/webdriver/common/service.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21#22# Base class implementing default behavior of service object,23# responsible for storing a service manager configuration.24#2526class Service27class << self28attr_reader :driver_path2930def chrome(**)31Chrome::Service.new(**)32end3334def firefox(**)35Firefox::Service.new(**)36end3738def ie(**)39IE::Service.new(**)40end41alias internet_explorer ie4243def edge(**)44Edge::Service.new(**)45end46alias microsoftedge edge47alias msedge edge4849def safari(**)50Safari::Service.new(**)51end5253def driver_path=(path)54Platform.assert_executable path if path.is_a?(String)55@driver_path = path56end57end5859attr_accessor :host, :executable_path, :port, :log, :args60alias extra_args args6162#63# End users should use a class method for the desired driver, rather than using this directly.64#65# @api private66#6768def initialize(path: nil, port: nil, log: nil, args: nil)69port ||= self.class::DEFAULT_PORT70args ||= []71path ||= env_path7273@executable_path = path74@host = Platform.localhost75@port = Integer(port)76@log = case log77when :stdout78$stdout79when :stderr80$stderr81else82log83end84@args = args8586raise Error::WebDriverError, "invalid port: #{@port}" if @port < 187end8889def launch90@executable_path ||= env_path || find_driver_path91ServiceManager.new(self).tap(&:start)92end9394def shutdown_supported95self.class::SHUTDOWN_SUPPORTED96end9798def find_driver_path99default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new100DriverFinder.new(default_options, self).driver_path101end102103def env_path104ENV.fetch(self.class::DRIVER_PATH_ENV_KEY, nil)105end106end # Service107end # WebDriver108end # Selenium109110111