webdrivers 3.8.0 → 3.8.1
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 +14 -0
- data/.gitignore +7 -7
- data/.rubocop.yml +35 -19
- data/.travis.yml +24 -16
- data/CHANGELOG.md +120 -113
- data/Gemfile +6 -4
- data/LICENSE.txt +22 -22
- data/README.md +154 -153
- data/Rakefile +9 -9
- data/appveyor.yml +23 -0
- data/lib/webdrivers.rb +28 -26
- data/lib/webdrivers/chromedriver.rb +161 -140
- data/lib/webdrivers/common.rb +221 -205
- data/lib/webdrivers/geckodriver.rb +41 -43
- data/lib/webdrivers/iedriver.rb +41 -43
- data/lib/webdrivers/logger.rb +111 -109
- data/lib/webdrivers/mswebdriver.rb +59 -57
- data/lib/webdrivers/selenium.rb +40 -38
- data/spec/spec_helper.rb +12 -5
- data/spec/webdrivers/chromedriver_spec.rb +129 -104
- data/spec/webdrivers/geckodriver_spec.rb +66 -60
- data/spec/webdrivers/i_edriver_spec.rb +41 -36
- data/spec/webdrivers/ms_webdriver_spec.rb +26 -24
- data/spec/webdrivers_proxy_support_spec.rb +53 -51
- data/webdrivers.gemspec +30 -27
- metadata +27 -4
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
RuboCop::RakeTask.new
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/appveyor.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
build: off
|
2
|
+
cache:
|
3
|
+
- vendor/bundle
|
4
|
+
environment:
|
5
|
+
matrix:
|
6
|
+
- RUBY_VERSION: 24
|
7
|
+
RAKE_TASK: spec
|
8
|
+
- RUBY_VERSION: 24
|
9
|
+
RAKE_TASK: rubocop
|
10
|
+
- RUBY_VERSION: 25
|
11
|
+
RAKE_TASK: spec
|
12
|
+
- RUBY_VERSION: 26
|
13
|
+
RAKE_TASK: spec
|
14
|
+
install:
|
15
|
+
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
|
16
|
+
- bundle config --local path vendor/bundle
|
17
|
+
- bundle install
|
18
|
+
before_test:
|
19
|
+
- ruby -v
|
20
|
+
- gem -v
|
21
|
+
- bundle -v
|
22
|
+
test_script:
|
23
|
+
- bundle exec rake %RAKE_TASK%
|
data/lib/webdrivers.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'webdrivers/
|
4
|
-
require 'webdrivers/
|
5
|
-
require 'webdrivers/
|
6
|
-
require 'webdrivers/
|
7
|
-
require 'webdrivers/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webdrivers/selenium'
|
4
|
+
require 'webdrivers/logger'
|
5
|
+
require 'webdrivers/common'
|
6
|
+
require 'webdrivers/chromedriver'
|
7
|
+
require 'webdrivers/geckodriver'
|
8
|
+
require 'webdrivers/iedriver'
|
9
|
+
require 'webdrivers/mswebdriver'
|
10
|
+
|
11
|
+
module Webdrivers
|
12
|
+
class << self
|
13
|
+
attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir
|
14
|
+
|
15
|
+
def logger
|
16
|
+
@logger ||= Webdrivers::Logger.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def net_http_ssl_fix
|
24
|
+
raise 'Webdrivers.net_http_ssl_fix is no longer available.' \
|
25
|
+
' Please see https://github.com/titusfortner/webdrivers#ssl_connect-errors.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,140 +1,161 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
def
|
62
|
-
|
63
|
-
end
|
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
|
-
|
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
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
module Webdrivers
|
7
|
+
class Chromedriver < Common
|
8
|
+
class << self
|
9
|
+
def current_version
|
10
|
+
Webdrivers.logger.debug 'Checking current version'
|
11
|
+
return nil unless downloaded?
|
12
|
+
|
13
|
+
ver = `#{binary} --version`
|
14
|
+
Webdrivers.logger.debug "Current #{binary} version: #{ver}"
|
15
|
+
|
16
|
+
# Matches 2.46, 2.46.628411 and 73.0.3683.75
|
17
|
+
normalize_version ver[/\d+\.\d+(\.\d+)?(\.\d+)?/]
|
18
|
+
end
|
19
|
+
|
20
|
+
def latest_version
|
21
|
+
return @latest_version if @latest_version
|
22
|
+
|
23
|
+
raise StandardError, 'Can not reach site' unless site_available?
|
24
|
+
|
25
|
+
# Versions before 70 do not have a LATEST_RELEASE file
|
26
|
+
return normalize_version('2.46') if release_version < normalize_version('70.0.3538')
|
27
|
+
|
28
|
+
latest_applicable = latest_point_release(release_version)
|
29
|
+
|
30
|
+
Webdrivers.logger.debug "Latest version available: #{latest_applicable}"
|
31
|
+
@latest_version = normalize_version(latest_applicable)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def latest_point_release(version)
|
37
|
+
release_file = "LATEST_RELEASE_#{version}"
|
38
|
+
begin
|
39
|
+
normalize_version(get(URI.join(base_url, release_file)))
|
40
|
+
rescue Net::HTTPServerException
|
41
|
+
latest_release = normalize_version(get(URI.join(base_url, 'LATEST_RELEASE')))
|
42
|
+
Webdrivers.logger.debug "Unable to find a driver for: #{version}"
|
43
|
+
|
44
|
+
msg = version > latest_release ? 'you appear to be using a non-production version of Chrome; ' : ''
|
45
|
+
msg = "#{msg}please set `Webdrivers::Chromedriver.version = <desired driver version>` to an known "\
|
46
|
+
'chromedriver version: https://chromedriver.storage.googleapis.com/index.html'
|
47
|
+
raise StandardError, msg
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def platform
|
52
|
+
if Selenium::WebDriver::Platform.linux?
|
53
|
+
'linux64'
|
54
|
+
elsif Selenium::WebDriver::Platform.mac?
|
55
|
+
'mac64'
|
56
|
+
else
|
57
|
+
'win32'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_name
|
62
|
+
Selenium::WebDriver::Platform.windows? ? 'chromedriver.exe' : 'chromedriver'
|
63
|
+
end
|
64
|
+
|
65
|
+
def base_url
|
66
|
+
'https://chromedriver.storage.googleapis.com'
|
67
|
+
end
|
68
|
+
|
69
|
+
def download_url
|
70
|
+
return @download_url if @download_url
|
71
|
+
|
72
|
+
url = "#{base_url}/#{desired_version}/chromedriver_#{platform}.zip"
|
73
|
+
Webdrivers.logger.debug "chromedriver URL: #{url}"
|
74
|
+
@download_url = url
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns release version from the currently installed Chrome version
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# 73.0.3683.75 -> 73.0.3683
|
81
|
+
def release_version
|
82
|
+
chrome = normalize_version(chrome_version)
|
83
|
+
normalize_version(chrome.segments[0..2].join('.'))
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns currently installed Chrome version
|
87
|
+
def chrome_version
|
88
|
+
ver = case platform
|
89
|
+
when 'win32'
|
90
|
+
chrome_on_windows
|
91
|
+
when 'linux64'
|
92
|
+
chrome_on_linux
|
93
|
+
when 'mac64'
|
94
|
+
chrome_on_mac
|
95
|
+
else
|
96
|
+
raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
|
97
|
+
end.chomp
|
98
|
+
|
99
|
+
raise StandardError, 'Failed to find Chrome binary or its version.' if ver.nil? || ver.empty?
|
100
|
+
|
101
|
+
Webdrivers.logger.debug "Browser version: #{ver}"
|
102
|
+
normalize_version ver[/\d+\.\d+\.\d+\.\d+/] # Google Chrome 73.0.3683.75 -> 73.0.3683.75
|
103
|
+
end
|
104
|
+
|
105
|
+
def chrome_on_windows
|
106
|
+
if browser_binary
|
107
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
108
|
+
return `powershell (Get-ItemProperty '#{browser_binary}').VersionInfo.ProductVersion`.strip
|
109
|
+
end
|
110
|
+
|
111
|
+
# Workaround for Google Chrome when using Jruby on Windows.
|
112
|
+
# @see https://github.com/titusfortner/webdrivers/issues/41
|
113
|
+
if RUBY_PLATFORM == 'java'
|
114
|
+
ver = 'powershell (Get-Item -Path ((Get-ItemProperty "HKLM:\\Software\\Microsoft' \
|
115
|
+
"\\Windows\\CurrentVersion\\App` Paths\\chrome.exe\").\\'(default)\\'))" \
|
116
|
+
'.VersionInfo.ProductVersion'
|
117
|
+
return `#{ver}`.strip
|
118
|
+
end
|
119
|
+
|
120
|
+
# Default to Google Chrome
|
121
|
+
reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
|
122
|
+
executable = `powershell (Get-ItemProperty '#{reg}' -Name '(default)').'(default)'`.strip
|
123
|
+
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
124
|
+
ps = "(Get-Item (Get-ItemProperty '#{reg}').'(default)').VersionInfo.ProductVersion"
|
125
|
+
`powershell #{ps}`.strip
|
126
|
+
end
|
127
|
+
|
128
|
+
def chrome_on_linux
|
129
|
+
if browser_binary
|
130
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
131
|
+
return `#{Shellwords.escape browser_binary} --product-version`.strip
|
132
|
+
end
|
133
|
+
|
134
|
+
# Default to Google Chrome
|
135
|
+
executable = `which google-chrome`.strip
|
136
|
+
Webdrivers.logger.debug "Browser executable: '#{executable}'"
|
137
|
+
`#{executable} --product-version`.strip
|
138
|
+
end
|
139
|
+
|
140
|
+
def chrome_on_mac
|
141
|
+
if browser_binary
|
142
|
+
Webdrivers.logger.debug "Browser executable: '#{browser_binary}'"
|
143
|
+
return `#{Shellwords.escape browser_binary} --version`.strip
|
144
|
+
end
|
145
|
+
|
146
|
+
# Default to Google Chrome
|
147
|
+
executable = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
148
|
+
Webdrivers.logger.debug "Browser executable: #{executable}"
|
149
|
+
`#{executable} --version`.strip
|
150
|
+
end
|
151
|
+
|
152
|
+
#
|
153
|
+
# Returns user defined browser executable path from Selenium::WebDrivers::Chrome#path.
|
154
|
+
#
|
155
|
+
def browser_binary
|
156
|
+
# For Chromium, Brave, or whatever else
|
157
|
+
Selenium::WebDriver::Chrome.path
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/lib/webdrivers/common.rb
CHANGED
@@ -1,205 +1,221 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
end
|
52
|
-
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
File.
|
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
|
-
File.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
def
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems/package'
|
4
|
+
require 'zip'
|
5
|
+
|
6
|
+
module Webdrivers
|
7
|
+
class Common
|
8
|
+
class << self
|
9
|
+
attr_accessor :version
|
10
|
+
|
11
|
+
def update
|
12
|
+
unless site_available?
|
13
|
+
return current_version.nil? ? nil : binary
|
14
|
+
end
|
15
|
+
|
16
|
+
# Newer not specified or latest not found, so use existing
|
17
|
+
return binary if desired_version.nil? && File.exist?(binary)
|
18
|
+
|
19
|
+
# Can't find desired and no existing binary
|
20
|
+
if desired_version.nil?
|
21
|
+
msg = "Unable to find the latest version of #{file_name}; try downloading manually " \
|
22
|
+
"from #{base_url} and place in #{install_dir}"
|
23
|
+
raise StandardError, msg
|
24
|
+
end
|
25
|
+
|
26
|
+
if correct_binary?
|
27
|
+
Webdrivers.logger.debug 'Expected webdriver version found'
|
28
|
+
return binary
|
29
|
+
end
|
30
|
+
|
31
|
+
remove # Remove outdated exe
|
32
|
+
download # Fetch latest
|
33
|
+
end
|
34
|
+
|
35
|
+
def desired_version
|
36
|
+
if version.is_a?(Gem::Version)
|
37
|
+
version
|
38
|
+
elsif version.nil?
|
39
|
+
latest_version
|
40
|
+
else
|
41
|
+
normalize_version(version)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def latest_version
|
46
|
+
return @latest_version if @latest_version
|
47
|
+
|
48
|
+
raise StandardError, 'Can not reach site' unless site_available?
|
49
|
+
|
50
|
+
@latest_version = downloads.keys.max
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove
|
54
|
+
max_attempts = 3
|
55
|
+
attempts_made = 0
|
56
|
+
delay = 0.5
|
57
|
+
Webdrivers.logger.debug "Deleting #{binary}"
|
58
|
+
@download_url = nil
|
59
|
+
|
60
|
+
begin
|
61
|
+
attempts_made += 1
|
62
|
+
File.delete binary if File.exist? binary
|
63
|
+
rescue Errno::EACCES # Solves an intermittent file locking issue on Windows
|
64
|
+
sleep(delay)
|
65
|
+
retry if File.exist?(binary) && attempts_made <= max_attempts
|
66
|
+
raise
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def download
|
71
|
+
raise StandardError, 'Can not reach site' unless site_available?
|
72
|
+
|
73
|
+
filename = File.basename download_url
|
74
|
+
|
75
|
+
FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
|
76
|
+
Dir.chdir install_dir do
|
77
|
+
df = Tempfile.open(['', filename], binmode: true) do |file|
|
78
|
+
file.print get(download_url)
|
79
|
+
file
|
80
|
+
end
|
81
|
+
|
82
|
+
raise "Could not download #{download_url}" unless File.exist? df.to_path
|
83
|
+
|
84
|
+
Webdrivers.logger.debug "Successfully downloaded #{df.to_path}"
|
85
|
+
|
86
|
+
decompress_file(df.to_path, filename)
|
87
|
+
Webdrivers.logger.debug 'Decompression Complete'
|
88
|
+
Webdrivers.logger.debug "Deleting #{df.to_path}"
|
89
|
+
df.close!
|
90
|
+
end
|
91
|
+
raise "Could not decompress #{download_url} to get #{binary}" unless File.exist?(binary)
|
92
|
+
|
93
|
+
FileUtils.chmod 'ugo+rx', binary
|
94
|
+
Webdrivers.logger.debug "Completed download and processing of #{binary}"
|
95
|
+
binary
|
96
|
+
end
|
97
|
+
|
98
|
+
def install_dir
|
99
|
+
Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
|
100
|
+
end
|
101
|
+
|
102
|
+
def binary
|
103
|
+
File.join install_dir, file_name
|
104
|
+
end
|
105
|
+
|
106
|
+
protected
|
107
|
+
|
108
|
+
def get(url, limit = 10)
|
109
|
+
raise StandardError, 'Too many HTTP redirects' if limit.zero?
|
110
|
+
|
111
|
+
response = http.get_response(URI(url))
|
112
|
+
Webdrivers.logger.debug "Get response: #{response.inspect}"
|
113
|
+
|
114
|
+
case response
|
115
|
+
when Net::HTTPSuccess
|
116
|
+
response.body
|
117
|
+
when Net::HTTPRedirection
|
118
|
+
location = response['location']
|
119
|
+
Webdrivers.logger.debug "Redirected to #{location}"
|
120
|
+
get(location, limit - 1)
|
121
|
+
else
|
122
|
+
response.value
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def http
|
127
|
+
if using_proxy
|
128
|
+
Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
|
129
|
+
Webdrivers.proxy_user, Webdrivers.proxy_pass)
|
130
|
+
else
|
131
|
+
Net::HTTP
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def download_url
|
138
|
+
@download_url ||= downloads[desired_version]
|
139
|
+
end
|
140
|
+
|
141
|
+
def using_proxy
|
142
|
+
Webdrivers.proxy_addr && Webdrivers.proxy_port
|
143
|
+
end
|
144
|
+
|
145
|
+
def downloaded?
|
146
|
+
result = File.exist? binary
|
147
|
+
Webdrivers.logger.debug "File is already downloaded: #{result}"
|
148
|
+
result
|
149
|
+
end
|
150
|
+
|
151
|
+
def site_available?
|
152
|
+
Webdrivers.logger.debug "Looking for Site: #{base_url}"
|
153
|
+
get(base_url)
|
154
|
+
Webdrivers.logger.debug "Found Site: #{base_url}"
|
155
|
+
true
|
156
|
+
rescue StandardError => e
|
157
|
+
Webdrivers.logger.debug e
|
158
|
+
false
|
159
|
+
end
|
160
|
+
|
161
|
+
def platform
|
162
|
+
if Selenium::WebDriver::Platform.linux?
|
163
|
+
"linux#{Selenium::WebDriver::Platform.bitsize}"
|
164
|
+
elsif Selenium::WebDriver::Platform.mac?
|
165
|
+
'mac'
|
166
|
+
else
|
167
|
+
'win'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def decompress_file(filename, target)
|
172
|
+
case filename
|
173
|
+
when /tar\.gz$/
|
174
|
+
Webdrivers.logger.debug 'Decompressing tar'
|
175
|
+
untargz_file(filename)
|
176
|
+
when /tar\.bz2$/
|
177
|
+
Webdrivers.logger.debug 'Decompressing bz2'
|
178
|
+
system "tar xjf #{filename}"
|
179
|
+
filename.gsub('.tar.bz2', '')
|
180
|
+
when /\.zip$/
|
181
|
+
Webdrivers.logger.debug 'Decompressing zip'
|
182
|
+
unzip_file(filename)
|
183
|
+
else
|
184
|
+
Webdrivers.logger.debug 'No Decompression needed'
|
185
|
+
FileUtils.cp(filename, File.join(Dir.pwd, target))
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def untargz_file(filename)
|
190
|
+
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(filename))
|
191
|
+
|
192
|
+
File.open(file_name, 'w+b') do |ucf|
|
193
|
+
tar_extract.each { |entry| ucf << entry.read }
|
194
|
+
File.basename ucf
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def unzip_file(filename)
|
199
|
+
Zip::File.open(filename) do |zip_file|
|
200
|
+
zip_file.each do |f|
|
201
|
+
@top_path ||= f.name
|
202
|
+
f_path = File.join(Dir.pwd, f.name)
|
203
|
+
FileUtils.rm_rf(f_path) if File.exist?(f_path)
|
204
|
+
FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
|
205
|
+
zip_file.extract(f, f_path)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
@top_path
|
209
|
+
end
|
210
|
+
|
211
|
+
# Already have latest version downloaded?
|
212
|
+
def correct_binary?
|
213
|
+
desired_version == current_version && File.exist?(binary)
|
214
|
+
end
|
215
|
+
|
216
|
+
def normalize_version(version)
|
217
|
+
Gem::Version.new(version.to_s)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|