+670
-346
lines changedFilter options
+670
-346
lines changed Original file line number Diff line number Diff line change
@@ -28,11 +28,10 @@ module Chrome
28
28
#
29
29
30
30
class Driver < Chromium::Driver
31
-
def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts)
32
-
raise ArgumentError, "Can't initialize #{self.class} with :url" if url
31
+
include LocalDriver
33
32
34
-
caps = process_options(options, capabilities)
35
-
url = service_url(service || Service.chrome)
33
+
def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts)
34
+
caps, url = initialize_local_driver(capabilities, options, service, url)
36
35
super(caps: caps, url: url, **opts)
37
36
end
38
37
@@ -45,16 +44,6 @@ def browser
45
44
def devtools_address
46
45
"http://#{capabilities['goog:chromeOptions']['debuggerAddress']}"
47
46
end
48
-
49
-
def process_options(options, capabilities)
50
-
if options && !options.is_a?(Options)
51
-
raise ArgumentError, ":options must be an instance of #{Options}"
52
-
elsif options.nil? && capabilities.nil?
53
-
options = Options.new
54
-
end
55
-
56
-
super(options, capabilities)
57
-
end
58
47
end # Driver
59
48
end # Chrome
60
49
end # WebDriver
Original file line number Diff line number Diff line change
@@ -25,11 +25,6 @@ module Chrome
25
25
class Service < Chromium::Service
26
26
DEFAULT_PORT = 9515
27
27
EXECUTABLE = 'chromedriver'
28
-
MISSING_TEXT = <<~ERROR
29
-
Unable to find chromedriver. Please download the server from
30
-
https://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH.
31
-
More info at https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/?language=ruby.
32
-
ERROR
33
28
SHUTDOWN_SUPPORTED = true
34
29
end # Service
35
30
end # Chrome
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
18
18
# under the License.
19
19
20
20
require 'selenium/webdriver/common/error'
21
+
require 'selenium/webdriver/common/local_driver'
22
+
require 'selenium/webdriver/common/driver_finder'
21
23
require 'selenium/webdriver/common/platform'
22
24
require 'selenium/webdriver/common/proxy'
23
25
require 'selenium/webdriver/common/log_entry'
Original file line number Diff line number Diff line change
@@ -318,24 +318,6 @@ def create_bridge(caps:, url:, http_client: nil)
318
318
end
319
319
end
320
320
321
-
def process_options(options, capabilities)
322
-
if options && capabilities
323
-
msg = "Don't use both :options and :capabilities when initializing #{self.class}, prefer :options"
324
-
raise ArgumentError, msg
325
-
end
326
-
327
-
options ? options.as_json : deprecate_capabilities(capabilities)
328
-
end
329
-
330
-
def deprecate_capabilities(capabilities)
331
-
unless is_a?(Remote::Driver)
332
-
WebDriver.logger.deprecate("The :capabilities parameter for #{self.class}",
333
-
":options argument with an instance of #{self.class}",
334
-
id: :capabilities)
335
-
end
336
-
generate_capabilities(capabilities)
337
-
end
338
-
339
321
def generate_capabilities(capabilities)
340
322
Array(capabilities).map { |cap|
341
323
if cap.is_a? Symbol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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, klass)
24
+
path = klass.driver_path
25
+
path = path.call if path.is_a?(Proc)
26
+
path ||= Platform.find_binary(klass::EXECUTABLE)
27
+
28
+
path ||= begin
29
+
SeleniumManager.driver_path(options)
30
+
rescue Error::WebDriverError => e
31
+
WebDriver.logger.debug("Unable obtain driver using Selenium Manager\n #{e.message}")
32
+
nil
33
+
end
34
+
msg = "Unable to locate the #{klass::EXECUTABLE} executable; for more information on how to install drivers, " \
35
+
'see https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/'
36
+
raise Error::WebDriverError, msg unless path
37
+
38
+
Platform.assert_executable path
39
+
path
40
+
end
41
+
end
42
+
end
43
+
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
+
module LocalDriver
23
+
def initialize_local_driver(capabilities, options, service, url)
24
+
raise ArgumentError, "Can't initialize #{self.class} with :url" if url
25
+
26
+
service ||= Service.send(browser)
27
+
caps = process_options(options, capabilities, service)
28
+
url = service_url(service)
29
+
30
+
[caps, url]
31
+
end
32
+
33
+
def process_options(options, capabilities, service)
34
+
default_options = Options.send(browser)
35
+
36
+
if options && capabilities
37
+
msg = "Don't use both :options and :capabilities when initializing #{self.class}, prefer :options"
38
+
raise ArgumentError, msg
39
+
elsif options && !options.is_a?(default_options.class)
40
+
raise ArgumentError, ":options must be an instance of #{default_options.class}"
41
+
elsif capabilities
42
+
WebDriver.logger.deprecate("The :capabilities parameter for #{self.class}",
43
+
":options argument with an instance of #{self.class}",
44
+
id: :capabilities)
45
+
generate_capabilities(capabilities)
46
+
else
47
+
options ||= default_options
48
+
service.executable_path ||= WebDriver::DriverFinder.path(options, service.class)
49
+
options.as_json
50
+
end
51
+
end
52
+
end
53
+
end
54
+
end
Original file line number Diff line number Diff line change
@@ -30,15 +30,24 @@ class SeleniumManager
30
30
BIN_PATH = '../../../../../bin'
31
31
32
32
class << self
33
-
# @param [String] driver_name which driver to use.
33
+
# @param [Options] options browser options.
34
34
# @return [String] the path to the correct driver.
35
-
def driver_path(driver_name)
36
-
unless %w[chromedriver geckodriver msedgedriver IEDriverServer].include?(driver_name)
37
-
msg = "Unable to locate driver with name: #{driver_name}"
38
-
raise Error::WebDriverError, msg
35
+
def driver_path(options)
36
+
unless options.is_a?(Options)
37
+
raise ArgumentError, "SeleniumManager requires a WebDriver::Options instance, not a #{options.inspect}"
39
38
end
40
39
41
-
location = run("#{binary} --driver #{driver_name}")
40
+
command = [binary, '--browser', options.browser_name]
41
+
if options.browser_version
42
+
command << '--browser-version'
43
+
command << options.browser_version
44
+
end
45
+
if options.respond_to?(:binary) && !options.binary.nil?
46
+
command << '--browser-path'
47
+
command << "\"#{options.binary.gsub('\ ', ' ').gsub(' ', '\ ')}\""
48
+
end
49
+
50
+
location = run(command.join(' '))
42
51
WebDriver.logger.debug("Driver found at #{location}")
43
52
Platform.assert_executable location
44
53
@@ -81,7 +90,7 @@ def run(command)
81
90
raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{stdout}#{stderr}"
82
91
end
83
92
84
-
stdout.gsub("INFO\t", '').strip
93
+
stdout.split("\n").last.gsub("INFO\t", '')
85
94
end
86
95
end
87
96
end # SeleniumManager
Original file line number Diff line number Diff line change
@@ -67,11 +67,10 @@ def driver_path=(path)
67
67
#
68
68
69
69
def initialize(path: nil, port: nil, args: nil)
70
-
path ||= self.class.driver_path
71
70
port ||= self.class::DEFAULT_PORT
72
71
args ||= []
73
72
74
-
@executable_path = binary_path(path)
73
+
@executable_path = path
75
74
@host = Platform.localhost
76
75
@port = Integer(port)
77
76
@@ -96,24 +95,6 @@ def extract_service_args(driver_opts)
96
95
id: :driver_opts)
97
96
driver_opts.key?(:args) ? driver_opts.delete(:args) : []
98
97
end
99
-
100
-
private
101
-
102
-
def binary_path(path = nil)
103
-
path = path.call if path.is_a?(Proc)
104
-
path ||= Platform.find_binary(self.class::EXECUTABLE)
105
-
106
-
begin
107
-
path ||= SeleniumManager.driver_path(self.class::EXECUTABLE)
108
-
rescue Error::WebDriverError => e
109
-
WebDriver.logger.debug("Unable obtain driver using Selenium Manager\n #{e.message}")
110
-
end
111
-
112
-
raise Error::WebDriverError, self.class::MISSING_TEXT unless path
113
-
114
-
Platform.assert_executable path
115
-
path
116
-
end
117
98
end # Service
118
99
end # WebDriver
119
100
end # Selenium
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ def stop
64
64
65
65
stop_server
66
66
@process.poll_for_exit STOP_TIMEOUT
67
-
rescue ChildProcess::TimeoutError
67
+
rescue ChildProcess::TimeoutError, Errno::ECONNREFUSED
68
68
nil # noop
69
69
ensure
70
70
stop_process
Original file line number Diff line number Diff line change
@@ -28,11 +28,10 @@ module Edge
28
28
#
29
29
30
30
class Driver < Chromium::Driver
31
-
def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts)
32
-
raise ArgumentError, "Can't initialize #{self.class} with :url" if url
31
+
include LocalDriver
33
32
34
-
caps = process_options(options, capabilities)
35
-
url = service_url(service || Service.edge)
33
+
def initialize(capabilities: nil, options: nil, service: nil, url: nil, **opts)
34
+
caps, url = initialize_local_driver(capabilities, options, service, url)
36
35
super(caps: caps, url: url, **opts)
37
36
end
38
37
@@ -45,16 +44,6 @@ def browser
45
44
def devtools_address
46
45
"http://#{capabilities['ms:edgeOptions']['debuggerAddress']}"
47
46
end
48
-
49
-
def process_options(options, capabilities)
50
-
if options && !options.is_a?(Options)
51
-
raise ArgumentError, ":options must be an instance of #{Options}"
52
-
elsif options.nil? && capabilities.nil?
53
-
options = Options.new
54
-
end
55
-
56
-
super(options, capabilities)
57
-
end
58
47
end # Driver
59
48
end # Edge
60
49
end # WebDriver
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4