webdrivers 3.9.2 → 3.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +13 -13
- data/.gitignore +7 -7
- data/.rubocop.yml +44 -44
- data/.travis.yml +24 -24
- data/CHANGELOG.md +137 -137
- data/Gemfile +6 -6
- data/LICENSE.txt +22 -22
- data/README.md +169 -169
- data/Rakefile +11 -11
- data/appveyor.yml +22 -22
- data/lib/webdrivers.rb +6 -6
- data/lib/webdrivers/chromedriver.rb +185 -185
- data/lib/webdrivers/common.rb +198 -191
- data/lib/webdrivers/geckodriver.rb +80 -80
- data/lib/webdrivers/iedriver.rb +70 -70
- data/lib/webdrivers/logger.rb +111 -111
- data/lib/webdrivers/mswebdriver.rb +55 -55
- data/lib/webdrivers/network.rb +61 -61
- data/lib/webdrivers/system.rb +154 -154
- data/spec/spec_helper.rb +18 -18
- data/spec/webdrivers/chromedriver_spec.rb +257 -257
- data/spec/webdrivers/geckodriver_spec.rb +210 -210
- data/spec/webdrivers/i_edriver_spec.rb +192 -192
- data/spec/webdrivers/ms_webdriver_spec.rb +30 -30
- data/spec/webdrivers_proxy_support_spec.rb +53 -53
- data/webdrivers.gemspec +31 -31
- metadata +11 -4
data/lib/webdrivers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'webdrivers/chromedriver'
|
4
|
-
require 'webdrivers/geckodriver'
|
5
|
-
require 'webdrivers/iedriver'
|
6
|
-
require 'webdrivers/mswebdriver'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webdrivers/chromedriver'
|
4
|
+
require 'webdrivers/geckodriver'
|
5
|
+
require 'webdrivers/iedriver'
|
6
|
+
require 'webdrivers/mswebdriver'
|
@@ -1,185 +1,185 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'shellwords'
|
4
|
-
require 'webdrivers/common'
|
5
|
-
|
6
|
-
module Webdrivers
|
7
|
-
class Chromedriver < Common
|
8
|
-
class << self
|
9
|
-
#
|
10
|
-
# Returns current chromedriver version.
|
11
|
-
#
|
12
|
-
# @return [Gem::Version]
|
13
|
-
def current_version
|
14
|
-
Webdrivers.logger.debug 'Checking current version'
|
15
|
-
return nil unless exists?
|
16
|
-
|
17
|
-
version = binary_version
|
18
|
-
return nil if version.nil?
|
19
|
-
|
20
|
-
# Matches 2.46, 2.46.628411 and 73.0.3683.75
|
21
|
-
normalize_version version[/\d+\.\d+(\.\d+)?(\.\d+)?/]
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# Returns latest available chromedriver version.
|
26
|
-
#
|
27
|
-
# @return [Gem::Version]
|
28
|
-
def latest_version
|
29
|
-
@latest_version ||= begin
|
30
|
-
# Versions before 70 do not have a LATEST_RELEASE file
|
31
|
-
return normalize_version('2.41') if release_version < normalize_version('70')
|
32
|
-
|
33
|
-
latest_applicable = with_cache(file_name) { latest_point_release(release_version) }
|
34
|
-
|
35
|
-
Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
|
36
|
-
normalize_version(latest_applicable)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Returns currently installed Chrome/Chromium version.
|
42
|
-
#
|
43
|
-
# @return [Gem::Version]
|
44
|
-
def chrome_version
|
45
|
-
ver = send("chrome_on_#{System.platform}").chomp
|
46
|
-
|
47
|
-
raise VersionError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
|
48
|
-
|
49
|
-
Webdrivers.logger.debug "Browser version: #{ver}"
|
50
|
-
normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def latest_point_release(version)
|
56
|
-
normalize_version(Network.get(URI.join(base_url, "LATEST_RELEASE_#{version}")))
|
57
|
-
rescue NetworkError
|
58
|
-
msg = "Unable to find latest point release version for #{version}."
|
59
|
-
msg = begin
|
60
|
-
latest_release = normalize_version(Network.get(URI.join(base_url, 'LATEST_RELEASE')))
|
61
|
-
if version > latest_release
|
62
|
-
"#{msg} You appear to be using a non-production version of Chrome."
|
63
|
-
else
|
64
|
-
msg
|
65
|
-
end
|
66
|
-
rescue NetworkError
|
67
|
-
"#{msg} A network issue is preventing determination of latest chromedriver release."
|
68
|
-
end
|
69
|
-
|
70
|
-
msg = "#{msg} Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` "\
|
71
|
-
'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
|
72
|
-
|
73
|
-
Webdrivers.logger.debug msg
|
74
|
-
raise VersionError, msg
|
75
|
-
end
|
76
|
-
|
77
|
-
def file_name
|
78
|
-
System.platform == 'win' ? 'chromedriver.exe' : 'chromedriver'
|
79
|
-
end
|
80
|
-
|
81
|
-
def base_url
|
82
|
-
'https://chromedriver.storage.googleapis.com'
|
83
|
-
end
|
84
|
-
|
85
|
-
def download_url
|
86
|
-
return @download_url if @download_url
|
87
|
-
|
88
|
-
version = if required_version == EMPTY_VERSION
|
89
|
-
latest_version
|
90
|
-
else
|
91
|
-
normalize_version(required_version)
|
92
|
-
end
|
93
|
-
|
94
|
-
file_name = System.platform == 'win' ? 'win32' : "#{System.platform}64"
|
95
|
-
url = "#{base_url}/#{version}/chromedriver_#{file_name}.zip"
|
96
|
-
Webdrivers.logger.debug "chromedriver URL: #{url}"
|
97
|
-
@download_url = url
|
98
|
-
end
|
99
|
-
|
100
|
-
# Returns release version from the currently installed Chrome version
|
101
|
-
#
|
102
|
-
# @example
|
103
|
-
# 73.0.3683.75 -> 73.0.3683
|
104
|
-
def release_version
|
105
|
-
chrome = normalize_version(chrome_version)
|
106
|
-
normalize_version(chrome.segments[0..2].join('.'))
|
107
|
-
end
|
108
|
-
|
109
|
-
def chrome_on_win
|
110
|
-
if browser_binary
|
111
|
-
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
112
|
-
return System.call("powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion").strip
|
113
|
-
end
|
114
|
-
|
115
|
-
# Workaround for Google Chrome when using Jruby on Windows.
|
116
|
-
# @see https://github.com/titusfortner/webdrivers/issues/41
|
117
|
-
if RUBY_PLATFORM == 'java'
|
118
|
-
ver = 'powershell (Get-Item -Path ((Get-ItemProperty "HKLM:\\Software\\Microsoft' \
|
119
|
-
"\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\'))" \
|
120
|
-
'.VersionInfo.ProductVersion'
|
121
|
-
return System.call(ver).strip
|
122
|
-
end
|
123
|
-
|
124
|
-
# Default to Google Chrome
|
125
|
-
reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
|
126
|
-
executable = System.call("powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'").strip
|
127
|
-
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
128
|
-
ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
|
129
|
-
System.call("powershell #{ps}").strip
|
130
|
-
end
|
131
|
-
|
132
|
-
def chrome_on_linux
|
133
|
-
if browser_binary
|
134
|
-
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
135
|
-
return System.call("#{Shellwords.escape browser_binary} --product-version").strip
|
136
|
-
end
|
137
|
-
|
138
|
-
# Default to Google Chrome
|
139
|
-
executable = System.call('which google-chrome').strip
|
140
|
-
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
141
|
-
System.call("#{executable} --product-version").strip
|
142
|
-
end
|
143
|
-
|
144
|
-
def chrome_on_mac
|
145
|
-
if browser_binary
|
146
|
-
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
147
|
-
return System.call("#{Shellwords.escape browser_binary} --version").strip
|
148
|
-
end
|
149
|
-
|
150
|
-
# Default to Google Chrome
|
151
|
-
executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
152
|
-
Webdrivers.logger.debug "Browser executable: #{executable}"
|
153
|
-
System.call("#{executable} --version").strip
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Returns user defined browser executable path from Selenium::WebDrivers::Chrome#path.
|
158
|
-
#
|
159
|
-
def browser_binary
|
160
|
-
# For Chromium, Brave, or whatever else
|
161
|
-
Selenium::WebDriver::Chrome.path
|
162
|
-
end
|
163
|
-
|
164
|
-
def sufficient_binary?
|
165
|
-
super && current_version && (current_version < normalize_version('70.0.3538') ||
|
166
|
-
current_version.segments.first == release_version.segments.first)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
if ::Selenium::WebDriver::Service.respond_to? :driver_path=
|
173
|
-
::Selenium::WebDriver::Chrome::Service.driver_path = proc { ::Webdrivers::Chromedriver.update }
|
174
|
-
else
|
175
|
-
# v3.141.0 and lower
|
176
|
-
module Selenium
|
177
|
-
module WebDriver
|
178
|
-
module Chrome
|
179
|
-
def self.driver_path
|
180
|
-
@driver_path ||= Webdrivers::Chromedriver.update
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shellwords'
|
4
|
+
require 'webdrivers/common'
|
5
|
+
|
6
|
+
module Webdrivers
|
7
|
+
class Chromedriver < Common
|
8
|
+
class << self
|
9
|
+
#
|
10
|
+
# Returns current chromedriver version.
|
11
|
+
#
|
12
|
+
# @return [Gem::Version]
|
13
|
+
def current_version
|
14
|
+
Webdrivers.logger.debug 'Checking current version'
|
15
|
+
return nil unless exists?
|
16
|
+
|
17
|
+
version = binary_version
|
18
|
+
return nil if version.nil?
|
19
|
+
|
20
|
+
# Matches 2.46, 2.46.628411 and 73.0.3683.75
|
21
|
+
normalize_version version[/\d+\.\d+(\.\d+)?(\.\d+)?/]
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Returns latest available chromedriver version.
|
26
|
+
#
|
27
|
+
# @return [Gem::Version]
|
28
|
+
def latest_version
|
29
|
+
@latest_version ||= begin
|
30
|
+
# Versions before 70 do not have a LATEST_RELEASE file
|
31
|
+
return normalize_version('2.41') if release_version < normalize_version('70')
|
32
|
+
|
33
|
+
latest_applicable = with_cache(file_name) { latest_point_release(release_version) }
|
34
|
+
|
35
|
+
Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
|
36
|
+
normalize_version(latest_applicable)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Returns currently installed Chrome/Chromium version.
|
42
|
+
#
|
43
|
+
# @return [Gem::Version]
|
44
|
+
def chrome_version
|
45
|
+
ver = send("chrome_on_#{System.platform}").chomp
|
46
|
+
|
47
|
+
raise VersionError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
|
48
|
+
|
49
|
+
Webdrivers.logger.debug "Browser version: #{ver}"
|
50
|
+
normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def latest_point_release(version)
|
56
|
+
normalize_version(Network.get(URI.join(base_url, "LATEST_RELEASE_#{version}")))
|
57
|
+
rescue NetworkError
|
58
|
+
msg = "Unable to find latest point release version for #{version}."
|
59
|
+
msg = begin
|
60
|
+
latest_release = normalize_version(Network.get(URI.join(base_url, 'LATEST_RELEASE')))
|
61
|
+
if version > latest_release
|
62
|
+
"#{msg} You appear to be using a non-production version of Chrome."
|
63
|
+
else
|
64
|
+
msg
|
65
|
+
end
|
66
|
+
rescue NetworkError
|
67
|
+
"#{msg} A network issue is preventing determination of latest chromedriver release."
|
68
|
+
end
|
69
|
+
|
70
|
+
msg = "#{msg} Please set `Webdrivers::Chromedriver.required_version = <desired driver version>` "\
|
71
|
+
'to a known chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
|
72
|
+
|
73
|
+
Webdrivers.logger.debug msg
|
74
|
+
raise VersionError, msg
|
75
|
+
end
|
76
|
+
|
77
|
+
def file_name
|
78
|
+
System.platform == 'win' ? 'chromedriver.exe' : 'chromedriver'
|
79
|
+
end
|
80
|
+
|
81
|
+
def base_url
|
82
|
+
'https://chromedriver.storage.googleapis.com'
|
83
|
+
end
|
84
|
+
|
85
|
+
def download_url
|
86
|
+
return @download_url if @download_url
|
87
|
+
|
88
|
+
version = if required_version == EMPTY_VERSION
|
89
|
+
latest_version
|
90
|
+
else
|
91
|
+
normalize_version(required_version)
|
92
|
+
end
|
93
|
+
|
94
|
+
file_name = System.platform == 'win' ? 'win32' : "#{System.platform}64"
|
95
|
+
url = "#{base_url}/#{version}/chromedriver_#{file_name}.zip"
|
96
|
+
Webdrivers.logger.debug "chromedriver URL: #{url}"
|
97
|
+
@download_url = url
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns release version from the currently installed Chrome version
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# 73.0.3683.75 -> 73.0.3683
|
104
|
+
def release_version
|
105
|
+
chrome = normalize_version(chrome_version)
|
106
|
+
normalize_version(chrome.segments[0..2].join('.'))
|
107
|
+
end
|
108
|
+
|
109
|
+
def chrome_on_win
|
110
|
+
if browser_binary
|
111
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
112
|
+
return System.call("powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion").strip
|
113
|
+
end
|
114
|
+
|
115
|
+
# Workaround for Google Chrome when using Jruby on Windows.
|
116
|
+
# @see https://github.com/titusfortner/webdrivers/issues/41
|
117
|
+
if RUBY_PLATFORM == 'java'
|
118
|
+
ver = 'powershell (Get-Item -Path ((Get-ItemProperty "HKLM:\\Software\\Microsoft' \
|
119
|
+
"\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\'))" \
|
120
|
+
'.VersionInfo.ProductVersion'
|
121
|
+
return System.call(ver).strip
|
122
|
+
end
|
123
|
+
|
124
|
+
# Default to Google Chrome
|
125
|
+
reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
|
126
|
+
executable = System.call("powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'").strip
|
127
|
+
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
128
|
+
ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
|
129
|
+
System.call("powershell #{ps}").strip
|
130
|
+
end
|
131
|
+
|
132
|
+
def chrome_on_linux
|
133
|
+
if browser_binary
|
134
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
135
|
+
return System.call("#{Shellwords.escape browser_binary} --product-version").strip
|
136
|
+
end
|
137
|
+
|
138
|
+
# Default to Google Chrome
|
139
|
+
executable = System.call('which google-chrome').strip
|
140
|
+
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
141
|
+
System.call("#{executable} --product-version").strip
|
142
|
+
end
|
143
|
+
|
144
|
+
def chrome_on_mac
|
145
|
+
if browser_binary
|
146
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
147
|
+
return System.call("#{Shellwords.escape browser_binary} --version").strip
|
148
|
+
end
|
149
|
+
|
150
|
+
# Default to Google Chrome
|
151
|
+
executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
152
|
+
Webdrivers.logger.debug "Browser executable: #{executable}"
|
153
|
+
System.call("#{executable} --version").strip
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Returns user defined browser executable path from Selenium::WebDrivers::Chrome#path.
|
158
|
+
#
|
159
|
+
def browser_binary
|
160
|
+
# For Chromium, Brave, or whatever else
|
161
|
+
Selenium::WebDriver::Chrome.path
|
162
|
+
end
|
163
|
+
|
164
|
+
def sufficient_binary?
|
165
|
+
super && current_version && (current_version < normalize_version('70.0.3538') ||
|
166
|
+
current_version.segments.first == release_version.segments.first)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
if ::Selenium::WebDriver::Service.respond_to? :driver_path=
|
173
|
+
::Selenium::WebDriver::Chrome::Service.driver_path = proc { ::Webdrivers::Chromedriver.update }
|
174
|
+
else
|
175
|
+
# v3.141.0 and lower
|
176
|
+
module Selenium
|
177
|
+
module WebDriver
|
178
|
+
module Chrome
|
179
|
+
def self.driver_path
|
180
|
+
@driver_path ||= Webdrivers::Chromedriver.update
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
data/lib/webdrivers/common.rb
CHANGED
@@ -1,191 +1,198 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubygems/package'
|
4
|
-
require 'zip'
|
5
|
-
require 'webdrivers/logger'
|
6
|
-
require 'webdrivers/network'
|
7
|
-
require 'webdrivers/system'
|
8
|
-
require 'selenium-webdriver'
|
9
|
-
|
10
|
-
module Webdrivers
|
11
|
-
class ConnectionError < StandardError
|
12
|
-
end
|
13
|
-
|
14
|
-
class VersionError < StandardError
|
15
|
-
end
|
16
|
-
|
17
|
-
class NetworkError < StandardError
|
18
|
-
end
|
19
|
-
|
20
|
-
class << self
|
21
|
-
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems/package'
|
4
|
+
require 'zip'
|
5
|
+
require 'webdrivers/logger'
|
6
|
+
require 'webdrivers/network'
|
7
|
+
require 'webdrivers/system'
|
8
|
+
require 'selenium-webdriver'
|
9
|
+
|
10
|
+
module Webdrivers
|
11
|
+
class ConnectionError < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
class VersionError < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
class NetworkError < StandardError
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir
|
22
|
+
|
23
|
+
#
|
24
|
+
# Returns the amount of time (Seconds) the gem waits between two update checks.
|
25
|
+
#
|
26
|
+
def cache_time
|
27
|
+
@cache_time || 0
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Set the amount of time (Seconds) the gem waits between two update checks. Disable
|
32
|
+
# Common.cache_warning.
|
33
|
+
#
|
34
|
+
def cache_time=(value)
|
35
|
+
Common.cache_warning = true
|
36
|
+
@cache_time = value
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
@logger ||= Webdrivers::Logger.new
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Provides a convenient way to configure the gem.
|
45
|
+
#
|
46
|
+
# @example Configure proxy and cache_time
|
47
|
+
# Webdrivers.configure do |config|
|
48
|
+
# config.proxy_addr = 'myproxy_address.com'
|
49
|
+
# config.proxy_port = '8080'
|
50
|
+
# config.proxy_user = 'username'
|
51
|
+
# config.proxy_pass = 'password'
|
52
|
+
# config.cache_time = 604_800 # 7 days
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
def configure
|
56
|
+
yield self
|
57
|
+
end
|
58
|
+
|
59
|
+
def net_http_ssl_fix
|
60
|
+
raise 'Webdrivers.net_http_ssl_fix is no longer available.' \
|
61
|
+
' Please see https://github.com/titusfortner/webdrivers#ssl_connect-errors.'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Common
|
66
|
+
class << self
|
67
|
+
attr_writer :required_version
|
68
|
+
attr_accessor :cache_warning
|
69
|
+
|
70
|
+
def version
|
71
|
+
Webdrivers.logger.deprecate("#{self.class}#version", "#{self.class}#required_version")
|
72
|
+
required_version
|
73
|
+
end
|
74
|
+
|
75
|
+
def version=(version)
|
76
|
+
Webdrivers.logger.deprecate("#{self.class}#version=", "#{self.class}#required_version=")
|
77
|
+
self.required_version = version
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Returns the user defined required version.
|
82
|
+
#
|
83
|
+
# @return [Gem::Version]
|
84
|
+
def required_version
|
85
|
+
normalize_version @required_version
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Triggers an update check.
|
90
|
+
#
|
91
|
+
# @return [String] Path to the driver binary.
|
92
|
+
def update
|
93
|
+
if correct_binary?
|
94
|
+
msg = required_version != EMPTY_VERSION ? 'The required webdriver version' : 'A working webdriver version'
|
95
|
+
Webdrivers.logger.debug "#{msg} is already on the system"
|
96
|
+
return driver_path
|
97
|
+
end
|
98
|
+
|
99
|
+
remove
|
100
|
+
System.download(download_url, driver_path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def desired_version
|
104
|
+
old = "#{self.class}#desired_version"
|
105
|
+
new = "#{self.class}#required_version or #{self.class}#latest_version"
|
106
|
+
Webdrivers.logger.deprecate(old, new)
|
107
|
+
|
108
|
+
desired_version == EMPTY_VERSION ? latest_version : normalize_version(desired_version)
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Deletes the existing driver binary.
|
113
|
+
#
|
114
|
+
def remove
|
115
|
+
@download_url = nil
|
116
|
+
@latest_version = nil
|
117
|
+
System.delete "#{System.install_dir}/#{file_name.gsub('.exe', '')}.version"
|
118
|
+
System.delete driver_path
|
119
|
+
end
|
120
|
+
|
121
|
+
def download
|
122
|
+
Webdrivers.logger.deprecate('#download', '#update')
|
123
|
+
System.download(download_url, driver_path)
|
124
|
+
end
|
125
|
+
|
126
|
+
def binary
|
127
|
+
Webdrivers.logger.deprecate('#binary', '#driver_path')
|
128
|
+
driver_path
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Returns path to the driver binary.
|
133
|
+
#
|
134
|
+
# @return [String]
|
135
|
+
def driver_path
|
136
|
+
File.join System.install_dir, file_name
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def download_url
|
142
|
+
@download_url ||= if required_version == EMPTY_VERSION
|
143
|
+
downloads[downloads.keys.max]
|
144
|
+
else
|
145
|
+
downloads[normalize_version(required_version)]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def exists?
|
150
|
+
System.exists? driver_path
|
151
|
+
end
|
152
|
+
|
153
|
+
def correct_binary?
|
154
|
+
current_version == if required_version == EMPTY_VERSION
|
155
|
+
latest_version
|
156
|
+
else
|
157
|
+
normalize_version(required_version)
|
158
|
+
end
|
159
|
+
rescue ConnectionError, VersionError
|
160
|
+
driver_path if sufficient_binary?
|
161
|
+
end
|
162
|
+
|
163
|
+
def sufficient_binary?
|
164
|
+
exists?
|
165
|
+
end
|
166
|
+
|
167
|
+
def normalize_version(version)
|
168
|
+
Gem::Version.new(version.to_s)
|
169
|
+
end
|
170
|
+
|
171
|
+
def binary_version
|
172
|
+
version = System.call("#{driver_path} --version")
|
173
|
+
Webdrivers.logger.debug "Current version of #{driver_path} is #{version}"
|
174
|
+
version
|
175
|
+
rescue Errno::ENOENT
|
176
|
+
Webdrivers.logger.debug "No Such File or Directory: #{driver_path}"
|
177
|
+
nil
|
178
|
+
end
|
179
|
+
|
180
|
+
def with_cache(file_name)
|
181
|
+
if System.valid_cache?(file_name)
|
182
|
+
normalize_version System.cached_version(file_name)
|
183
|
+
else
|
184
|
+
unless cache_warning
|
185
|
+
Webdrivers.logger.warn 'Driver caching is turned off in this version, but will be '\
|
186
|
+
'enabled by default in 4.x. Set the value with `Webdrivers#cache_time=` in seconds'
|
187
|
+
@cache_warning = true
|
188
|
+
end
|
189
|
+
version = yield
|
190
|
+
System.cache_version(file_name, version)
|
191
|
+
normalize_version version
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
EMPTY_VERSION = Gem::Version.new('')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|