|
20 | 20 | module Selenium |
21 | 21 | module WebDriver |
22 | 22 | class DriverFinder |
23 | | - def self.results(options, klass) |
24 | | - path = klass.driver_path |
25 | | - path = path.call if path.is_a?(Proc) |
| 23 | + class << self |
| 24 | + def results(options, klass) |
| 25 | + path = klass.driver_path |
| 26 | + path = path.call if path.is_a?(Proc) |
| 27 | + exe = klass::EXECUTABLE |
26 | 28 |
|
27 | | - results = if path |
28 | | - {driver_path: path} |
29 | | - else |
30 | | - begin |
31 | | - SeleniumManager.results(to_args(options)) |
32 | | - rescue StandardError => e |
33 | | - raise Error::NoSuchDriverError, |
34 | | - "Unable to obtain #{klass::EXECUTABLE} using Selenium Manager; #{e.message}" |
35 | | - end |
36 | | - end |
37 | | - |
38 | | - begin |
39 | | - Platform.assert_executable(results[:driver_path]) |
40 | | - rescue TypeError |
41 | | - raise Error::NoSuchDriverError, "Unable to locate or obtain #{klass::EXECUTABLE}" |
42 | | - rescue Error::WebDriverError => e |
43 | | - raise Error::NoSuchDriverError, "#{klass::EXECUTABLE} located, but: #{e.message}" |
| 29 | + if path |
| 30 | + validate_files(exe, driver_path: path) |
| 31 | + else |
| 32 | + begin |
| 33 | + validate_files(exe, **SeleniumManager.results(to_args(options))) |
| 34 | + rescue StandardError => e |
| 35 | + raise Error::NoSuchDriverError("Unable to obtain #{exe} using Selenium Manager"), e.message, e.backtrace |
| 36 | + end |
| 37 | + end |
44 | 38 | end |
45 | 39 |
|
46 | | - results |
47 | | - end |
| 40 | + def path(options, klass) |
| 41 | + WebDriver.logger.deprecate('`DriverFinder.path`', '`DriverFinder.results`', id: :driver_finder) |
| 42 | + results(options, klass)[:driver_path] |
| 43 | + end |
48 | 44 |
|
49 | | - def self.path(options, klass) |
50 | | - WebDriver.logger.deprecate('`DriverFinder.path`', '`DriverFinder.results`', id: :driver_finder) |
51 | | - results(options, klass)[:driver_path] |
52 | | - end |
| 45 | + private |
53 | 46 |
|
54 | | - def self.to_args(options) |
55 | | - args = ['--browser', options.browser_name] |
56 | | - if options.browser_version |
57 | | - args << '--browser-version' |
58 | | - args << options.browser_version |
| 47 | + def to_args(options) |
| 48 | + args = ['--browser', options.browser_name] |
| 49 | + if options.browser_version |
| 50 | + args << '--browser-version' |
| 51 | + args << options.browser_version |
| 52 | + end |
| 53 | + if options.respond_to?(:binary) && !options.binary.nil? |
| 54 | + args << '--browser-path' |
| 55 | + args << options.binary.gsub('\\', '\\\\\\') |
| 56 | + end |
| 57 | + if options.proxy |
| 58 | + args << '--proxy' |
| 59 | + args << (options.proxy.ssl || options.proxy.http) |
| 60 | + end |
| 61 | + args |
59 | 62 | end |
60 | | - if options.respond_to?(:binary) && !options.binary.nil? |
61 | | - args << '--browser-path' |
62 | | - args << options.binary.gsub('\\', '\\\\\\') |
63 | | - end |
64 | | - if options.proxy |
65 | | - args << '--proxy' |
66 | | - args << (options.proxy.ssl || options.proxy.http) |
| 63 | + |
| 64 | + def validate_files(exe, **opts) |
| 65 | + opts.each_value do |value| |
| 66 | + raise Error::NoSuchDriverError("Unable to locate or obtain #{exe})") if value.nil? |
| 67 | + |
| 68 | + Platform.assert_executable(value) |
| 69 | + rescue Error::WebDriverError => e |
| 70 | + raise Error::NoSuchDriverError("#{exe} located, but has problems"), e.message, e.backtrace |
| 71 | + end |
| 72 | + opts |
67 | 73 | end |
68 | | - args |
69 | 74 | end |
70 | 75 | end |
71 | 76 | end |
|
0 commit comments