Path: blob/trunk/rb/lib/selenium/webdriver/common/driver_finder.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 WebDriver21class DriverFinder22def self.path(options, service_class)23WebDriver.logger.deprecate('DriverFinder.path(options, service_class)',24'DriverFinder.new(options, service).driver_path')25new(options, service_class.new).driver_path26end2728def initialize(options, service)29@options = options30@service = service31end3233def browser_path34paths[:browser_path]35end3637def driver_path38paths[:driver_path]39end4041def browser_path?42!browser_path.nil? && !browser_path.empty?43end4445private4647def paths48@paths ||= begin49path = @service.class.driver_path50path = path.call if path.is_a?(Proc)51exe = @service.class::EXECUTABLE52if path53WebDriver.logger.debug("Skipping Selenium Manager; path to #{exe} specified in service class: #{path}")54Platform.assert_executable(path)55{driver_path: path}56else57output = SeleniumManager.binary_paths(*to_args)58formatted = {driver_path: Platform.cygwin_path(output['driver_path'], only_cygwin: true),59browser_path: Platform.cygwin_path(output['browser_path'], only_cygwin: true)}60Platform.assert_executable(formatted[:driver_path])6162browser_path = formatted[:browser_path]63Platform.assert_executable(browser_path)64if @options.respond_to?(:binary) && @options.binary.nil?65@options.binary = browser_path66@options.browser_version = nil67end6869formatted70end71rescue StandardError => e72WebDriver.logger.error("Exception occurred: #{e.message}")73WebDriver.logger.error("Backtrace:\n\t#{e.backtrace&.join("\n\t")}")74raise Error::NoSuchDriverError, "Unable to obtain #{exe}"75end76end7778def to_args79args = ['--browser', @options.browser_name]80if @options.browser_version81args << '--browser-version'82args << @options.browser_version83end84if @options.respond_to?(:binary) && !@options.binary.nil?85args << '--browser-path'86args << @options.binary.gsub('\\', '\\\\\\')87end88if @options.proxy89args << '--proxy'90args << (@options.proxy.ssl || @options.proxy.http)91end92args93end94end95end96end979899