Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/driver_finder.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
module Selenium
21
module WebDriver
22
class DriverFinder
23
def self.path(options, service_class)
24
WebDriver.logger.deprecate('DriverFinder.path(options, service_class)',
25
'DriverFinder.new(options, service).driver_path')
26
new(options, service_class.new).driver_path
27
end
28
29
def initialize(options, service)
30
@options = options
31
@service = service
32
end
33
34
def browser_path
35
paths[:browser_path]
36
end
37
38
def driver_path
39
paths[:driver_path]
40
end
41
42
def browser_path?
43
!browser_path.nil? && !browser_path.empty?
44
end
45
46
private
47
48
def paths
49
@paths ||= begin
50
path = @service.class.driver_path
51
path = path.call if path.is_a?(Proc)
52
exe = @service.class::EXECUTABLE
53
if path
54
WebDriver.logger.debug("Skipping Selenium Manager; path to #{exe} specified in service class: #{path}")
55
Platform.assert_executable(path)
56
{driver_path: path}
57
else
58
output = SeleniumManager.binary_paths(*to_args)
59
formatted = {driver_path: Platform.cygwin_path(output['driver_path'], only_cygwin: true),
60
browser_path: Platform.cygwin_path(output['browser_path'], only_cygwin: true)}
61
Platform.assert_executable(formatted[:driver_path])
62
63
browser_path = formatted[:browser_path]
64
Platform.assert_executable(browser_path)
65
if @options.respond_to?(:binary) && @options.binary.nil?
66
@options.binary = browser_path
67
@options.browser_version = nil
68
end
69
70
formatted
71
end
72
rescue StandardError => e
73
WebDriver.logger.error("Exception occurred: #{e.message}")
74
WebDriver.logger.error("Backtrace:\n\t#{e.backtrace&.join("\n\t")}")
75
raise Error::NoSuchDriverError, "Unable to obtain #{exe}"
76
end
77
end
78
79
def to_args
80
args = ['--browser', @options.browser_name]
81
if @options.browser_version
82
args << '--browser-version'
83
args << @options.browser_version
84
end
85
if @options.respond_to?(:binary) && !@options.binary.nil?
86
args << '--browser-path'
87
args << @options.binary.gsub('\\', '\\\\\\')
88
end
89
if @options.proxy
90
args << '--proxy'
91
args << (@options.proxy.ssl || @options.proxy.http)
92
end
93
args
94
end
95
end
96
end
97
end
98
99