webdrivers 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/webdrivers.rb CHANGED
@@ -1,27 +1,27 @@
1
- require "webdrivers/selenium"
2
- require "webdrivers/logger"
3
- require "webdrivers/common"
4
- require "webdrivers/chromedriver"
5
- require "webdrivers/geckodriver"
6
- require "webdrivers/iedriver"
7
- require "webdrivers/mswebdriver"
8
-
9
- module Webdrivers
10
-
11
- class << self
12
-
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
- require "net_http_ssl_fix"
25
- end
26
- end
27
- end
1
+ require "webdrivers/selenium"
2
+ require "webdrivers/logger"
3
+ require "webdrivers/common"
4
+ require "webdrivers/chromedriver"
5
+ require "webdrivers/geckodriver"
6
+ require "webdrivers/iedriver"
7
+ require "webdrivers/mswebdriver"
8
+
9
+ module Webdrivers
10
+
11
+ class << self
12
+
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
+ require "net_http_ssl_fix"
25
+ end
26
+ end
27
+ end
@@ -1,48 +1,91 @@
1
- require 'nokogiri'
2
-
3
- module Webdrivers
4
- class Chromedriver < Common
5
- class << self
6
-
7
- def current_version
8
- Webdrivers.logger.debug "Checking current version"
9
- return nil unless downloaded?
10
- string = %x(#{binary} --version)
11
- Webdrivers.logger.debug "Current version of #{binary} is #{string}"
12
- normalize string.match(/ChromeDriver (\d+\.\d+)/)[1]
13
- end
14
-
15
- def latest_version
16
- raise StandardError, "Can not reach site" unless site_available?
17
- Gem::Version.new(get(URI.join(base_url, "LATEST_RELEASE")))
18
- end
19
-
20
- private
21
-
22
- def file_name
23
- platform == "win" ? "chromedriver.exe" : "chromedriver"
24
- end
25
-
26
- def base_url
27
- 'http://chromedriver.storage.googleapis.com'
28
- end
29
-
30
- def downloads
31
- Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
32
-
33
- @downloads ||= begin
34
- doc = Nokogiri::XML.parse(get(base_url))
35
- items = doc.css("Contents Key").collect(&:text)
36
- items.select! {|item| item.include?(platform)}
37
- ds = items.each_with_object({}) do |item, hash|
38
- key = normalize item[/^[^\/]+/]
39
- hash[key] = "#{base_url}/#{item}"
40
- end
41
- Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
42
- ds
43
- end
44
- end
45
-
46
- end
47
- end
48
- end
1
+ require 'nokogiri'
2
+
3
+ module Webdrivers
4
+ class Chromedriver < Common
5
+ class << self
6
+
7
+ def current_version
8
+ Webdrivers.logger.debug "Checking current version"
9
+ return nil unless downloaded?
10
+ string = %x(#{binary} --version)
11
+ Webdrivers.logger.debug "Current version of #{binary} is #{string}"
12
+ normalize string.match(/ChromeDriver (\d+\.\d+)/)[1]
13
+ end
14
+
15
+ def latest_version
16
+ raise StandardError, "Can not reach site" unless site_available?
17
+
18
+ # Latest webdriver release for installed Chrome version
19
+ release_file = "LATEST_RELEASE_#{release_version}"
20
+ latest_available = get(URI.join(base_url, release_file))
21
+ Gem::Version.new(latest_available)
22
+ end
23
+
24
+ private
25
+
26
+ def file_name
27
+ platform == "win" ? "chromedriver.exe" : "chromedriver"
28
+ end
29
+
30
+ def base_url
31
+ 'https://chromedriver.storage.googleapis.com'
32
+ end
33
+
34
+ def downloads
35
+ Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
36
+
37
+ @downloads ||= begin
38
+ doc = Nokogiri::XML.parse(get(base_url))
39
+ items = doc.css("Contents Key").collect(&:text)
40
+ items.select! { |item| item.include?(platform) }
41
+ ds = items.each_with_object({}) do |item, hash|
42
+ key = normalize item[/^[^\/]+/]
43
+ hash[key] = "#{base_url}/#{item}"
44
+ end
45
+ Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
46
+ ds
47
+ end
48
+ end
49
+
50
+ # Returns release version from the currently installed Chrome version
51
+ #
52
+ # @example
53
+ # 73.0.3683.75 -> 73.0.3683
54
+ def release_version
55
+ chrome_version[/\d+\.\d+\.\d+/]
56
+ end
57
+
58
+ # Returns currently installed Chrome version
59
+ def chrome_version
60
+ ver = case platform
61
+ when 'win'
62
+ chrome_on_windows
63
+ when /linux/
64
+ chrome_on_linux
65
+ when 'mac'
66
+ chrome_on_mac
67
+ else
68
+ raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
69
+ end.chomp
70
+
71
+ # Google Chrome 73.0.3683.75 -> 73.0.3683.75
72
+ ver[/(\d|\.)+/]
73
+ end
74
+
75
+ def chrome_on_windows
76
+ reg = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
77
+ ps = "(Get-Item (Get-ItemProperty '#{reg}').'(Default)').VersionInfo.ProductVersion"
78
+ `powershell #{ps}`
79
+ end
80
+
81
+ def chrome_on_linux
82
+ `google-chrome --version`
83
+ end
84
+
85
+ def chrome_on_mac
86
+ loc = Shellwords.escape '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
87
+ `#{loc} --version`
88
+ end
89
+ end
90
+ end
91
+ end
@@ -1,204 +1,204 @@
1
- require 'rubygems/package'
2
- require 'zip'
3
-
4
- module Webdrivers
5
- class Common
6
- class << self
7
-
8
- attr_accessor :version
9
-
10
- def update
11
- unless site_available?
12
- return current_version.nil? ? nil : binary
13
- end
14
-
15
- # Newer not specified or latest not found, so use existing
16
- return binary if desired_version.nil? && File.exists?(binary)
17
-
18
- # Can't find desired and no existing binary
19
- if desired_version.nil?
20
- msg = "Unable to find the latest version of #{file_name}; try downloading manually from #{base_url} and place in #{install_dir}"
21
- raise StandardError, msg
22
- end
23
-
24
- if correct_binary?
25
- Webdrivers.logger.debug "Expected webdriver version found"
26
- return binary
27
- end
28
-
29
- remove # Remove outdated exe
30
- download # Fetch latest
31
- end
32
-
33
- def desired_version
34
- if self.version.is_a?(Gem::Version)
35
- version
36
- elsif self.version.nil?
37
- latest_version
38
- else
39
- Gem::Version.new(self.version.to_s)
40
- end
41
- end
42
-
43
- def latest_version
44
- raise StandardError, "Can not reach site" unless site_available?
45
-
46
- downloads.keys.sort.last
47
- end
48
-
49
- def remove
50
- Webdrivers.logger.debug "Deleting #{binary}"
51
- FileUtils.rm_f binary
52
- end
53
-
54
- def download
55
- raise StandardError, "Can not reach site" unless site_available?
56
-
57
- url = downloads[desired_version]
58
- filename = File.basename url
59
-
60
- FileUtils.mkdir_p(install_dir) unless File.exists?(install_dir)
61
- Dir.chdir install_dir do
62
- FileUtils.rm_f filename
63
- open(filename, "wb") do |file|
64
- file.print get(url)
65
- end
66
- raise "Could not download #{url}" unless File.exists? filename
67
- Webdrivers.logger.debug "Successfully downloaded #{filename}"
68
- dcf = decompress_file(filename)
69
- Webdrivers.logger.debug "Decompression Complete"
70
- if dcf
71
- Webdrivers.logger.debug "Deleting #{filename}"
72
- FileUtils.rm_f filename
73
- end
74
- if respond_to? :extract_file
75
- Webdrivers.logger.debug "Extracting #{dcf}"
76
- extract_file(dcf)
77
- end
78
- end
79
- raise "Could not decompress #{filename} to get #{binary}" unless File.exists?(binary)
80
- FileUtils.chmod "ugo+rx", binary
81
- Webdrivers.logger.debug "Completed download and processing of #{binary}"
82
- binary
83
- end
84
-
85
- def install_dir
86
- Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], ".webdrivers"))
87
- end
88
-
89
- def binary
90
- File.join install_dir, file_name
91
- end
92
-
93
- protected
94
-
95
- def get(url, limit = 10)
96
- raise StandardError, 'Too many HTTP redirects' if limit == 0
97
-
98
- response = http.get_response(URI(url))
99
- Webdrivers.logger.debug "Get response: #{response.inspect}"
100
-
101
- case response
102
- when Net::HTTPSuccess
103
- response.body
104
- when Net::HTTPRedirection
105
- location = response['location']
106
- Webdrivers.logger.debug "Redirected to #{location}"
107
- get(location, limit - 1)
108
- else
109
- response.value
110
- end
111
- end
112
-
113
- def http
114
- if using_proxy
115
- Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
116
- Webdrivers.proxy_user, Webdrivers.proxy_pass)
117
- else
118
- Net::HTTP
119
- end
120
- end
121
-
122
- private
123
-
124
- def using_proxy
125
- Webdrivers.proxy_addr && Webdrivers.proxy_port
126
- end
127
-
128
- def downloaded?
129
- result = File.exist? binary
130
- Webdrivers.logger.debug "File is already downloaded: #{result}"
131
- result
132
- end
133
-
134
- def site_available?
135
- Webdrivers.logger.debug "Looking for Site: #{base_url}"
136
- get(base_url)
137
- Webdrivers.logger.debug "Found Site: #{base_url}"
138
- true
139
- rescue StandardError => ex
140
- Webdrivers.logger.debug ex.inspect
141
- false
142
- end
143
-
144
- def platform
145
- if Selenium::WebDriver::Platform.linux?
146
- "linux#{Selenium::WebDriver::Platform.bitsize}"
147
- elsif Selenium::WebDriver::Platform.mac?
148
- 'mac'
149
- else
150
- 'win'
151
- end
152
- end
153
-
154
- def decompress_file(filename)
155
- case filename
156
- when /tar\.gz$/
157
- Webdrivers.logger.debug "Decompressing tar"
158
- untargz_file(filename)
159
- when /tar\.bz2$/
160
- Webdrivers.logger.debug "Decompressing bz2"
161
- system "tar xjf #{filename}"
162
- filename.gsub('.tar.bz2', '')
163
- when /\.zip$/
164
- Webdrivers.logger.debug "Decompressing zip"
165
- unzip_file(filename)
166
- else
167
- Webdrivers.logger.debug "No Decompression needed"
168
- nil
169
- end
170
- end
171
-
172
- def untargz_file(filename)
173
- tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(filename))
174
-
175
- File.open(file_name, "w+b") do |ucf|
176
- tar_extract.each { |entry| ucf << entry.read }
177
- File.basename ucf
178
- end
179
- end
180
-
181
- def unzip_file(filename)
182
- Zip::File.open("#{Dir.pwd}/#{filename}") do |zip_file|
183
- zip_file.each do |f|
184
- @top_path ||= f.name
185
- f_path = File.join(Dir.pwd, f.name)
186
- FileUtils.rm_rf(f_path) if File.exist?(f_path)
187
- FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
188
- zip_file.extract(f, f_path)
189
- end
190
- end
191
- @top_path
192
- end
193
-
194
- # Already have latest version downloaded?
195
- def correct_binary?
196
- desired_version == current_version && File.exists?(binary)
197
- end
198
-
199
- def normalize(string)
200
- Gem::Version.new(string)
201
- end
202
- end
203
- end
1
+ require 'rubygems/package'
2
+ require 'zip'
3
+
4
+ module Webdrivers
5
+ class Common
6
+ class << self
7
+
8
+ attr_accessor :version
9
+
10
+ def update
11
+ unless site_available?
12
+ return current_version.nil? ? nil : binary
13
+ end
14
+
15
+ # Newer not specified or latest not found, so use existing
16
+ return binary if desired_version.nil? && File.exists?(binary)
17
+
18
+ # Can't find desired and no existing binary
19
+ if desired_version.nil?
20
+ msg = "Unable to find the latest version of #{file_name}; try downloading manually from #{base_url} and place in #{install_dir}"
21
+ raise StandardError, msg
22
+ end
23
+
24
+ if correct_binary?
25
+ Webdrivers.logger.debug "Expected webdriver version found"
26
+ return binary
27
+ end
28
+
29
+ remove # Remove outdated exe
30
+ download # Fetch latest
31
+ end
32
+
33
+ def desired_version
34
+ if self.version.is_a?(Gem::Version)
35
+ version
36
+ elsif self.version.nil?
37
+ latest_version
38
+ else
39
+ Gem::Version.new(self.version.to_s)
40
+ end
41
+ end
42
+
43
+ def latest_version
44
+ raise StandardError, "Can not reach site" unless site_available?
45
+
46
+ downloads.keys.sort.last
47
+ end
48
+
49
+ def remove
50
+ Webdrivers.logger.debug "Deleting #{binary}"
51
+ FileUtils.rm_f binary
52
+ end
53
+
54
+ def download
55
+ raise StandardError, "Can not reach site" unless site_available?
56
+
57
+ url = downloads[desired_version]
58
+ filename = File.basename url
59
+
60
+ FileUtils.mkdir_p(install_dir) unless File.exists?(install_dir)
61
+ Dir.chdir install_dir do
62
+ FileUtils.rm_f filename
63
+ open(filename, "wb") do |file|
64
+ file.print get(url)
65
+ end
66
+ raise "Could not download #{url}" unless File.exists? filename
67
+ Webdrivers.logger.debug "Successfully downloaded #{filename}"
68
+ dcf = decompress_file(filename)
69
+ Webdrivers.logger.debug "Decompression Complete"
70
+ if dcf
71
+ Webdrivers.logger.debug "Deleting #{filename}"
72
+ FileUtils.rm_f filename
73
+ end
74
+ if respond_to? :extract_file
75
+ Webdrivers.logger.debug "Extracting #{dcf}"
76
+ extract_file(dcf)
77
+ end
78
+ end
79
+ raise "Could not decompress #{filename} to get #{binary}" unless File.exists?(binary)
80
+ FileUtils.chmod "ugo+rx", binary
81
+ Webdrivers.logger.debug "Completed download and processing of #{binary}"
82
+ binary
83
+ end
84
+
85
+ def install_dir
86
+ Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], ".webdrivers"))
87
+ end
88
+
89
+ def binary
90
+ File.join install_dir, file_name
91
+ end
92
+
93
+ protected
94
+
95
+ def get(url, limit = 10)
96
+ raise StandardError, 'Too many HTTP redirects' if limit == 0
97
+
98
+ response = http.get_response(URI(url))
99
+ Webdrivers.logger.debug "Get response: #{response.inspect}"
100
+
101
+ case response
102
+ when Net::HTTPSuccess
103
+ response.body
104
+ when Net::HTTPRedirection
105
+ location = response['location']
106
+ Webdrivers.logger.debug "Redirected to #{location}"
107
+ get(location, limit - 1)
108
+ else
109
+ response.value
110
+ end
111
+ end
112
+
113
+ def http
114
+ if using_proxy
115
+ Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
116
+ Webdrivers.proxy_user, Webdrivers.proxy_pass)
117
+ else
118
+ Net::HTTP
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def using_proxy
125
+ Webdrivers.proxy_addr && Webdrivers.proxy_port
126
+ end
127
+
128
+ def downloaded?
129
+ result = File.exist? binary
130
+ Webdrivers.logger.debug "File is already downloaded: #{result}"
131
+ result
132
+ end
133
+
134
+ def site_available?
135
+ Webdrivers.logger.debug "Looking for Site: #{base_url}"
136
+ get(base_url)
137
+ Webdrivers.logger.debug "Found Site: #{base_url}"
138
+ true
139
+ rescue StandardError => ex
140
+ Webdrivers.logger.debug ex.inspect
141
+ false
142
+ end
143
+
144
+ def platform
145
+ if Selenium::WebDriver::Platform.linux?
146
+ "linux#{Selenium::WebDriver::Platform.bitsize}"
147
+ elsif Selenium::WebDriver::Platform.mac?
148
+ 'mac'
149
+ else
150
+ 'win'
151
+ end
152
+ end
153
+
154
+ def decompress_file(filename)
155
+ case filename
156
+ when /tar\.gz$/
157
+ Webdrivers.logger.debug "Decompressing tar"
158
+ untargz_file(filename)
159
+ when /tar\.bz2$/
160
+ Webdrivers.logger.debug "Decompressing bz2"
161
+ system "tar xjf #{filename}"
162
+ filename.gsub('.tar.bz2', '')
163
+ when /\.zip$/
164
+ Webdrivers.logger.debug "Decompressing zip"
165
+ unzip_file(filename)
166
+ else
167
+ Webdrivers.logger.debug "No Decompression needed"
168
+ nil
169
+ end
170
+ end
171
+
172
+ def untargz_file(filename)
173
+ tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(filename))
174
+
175
+ File.open(file_name, "w+b") do |ucf|
176
+ tar_extract.each { |entry| ucf << entry.read }
177
+ File.basename ucf
178
+ end
179
+ end
180
+
181
+ def unzip_file(filename)
182
+ Zip::File.open("#{Dir.pwd}/#{filename}") do |zip_file|
183
+ zip_file.each do |f|
184
+ @top_path ||= f.name
185
+ f_path = File.join(Dir.pwd, f.name)
186
+ FileUtils.rm_rf(f_path) if File.exist?(f_path)
187
+ FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
188
+ zip_file.extract(f, f_path)
189
+ end
190
+ end
191
+ @top_path
192
+ end
193
+
194
+ # Already have latest version downloaded?
195
+ def correct_binary?
196
+ desired_version == current_version && File.exists?(binary)
197
+ end
198
+
199
+ def normalize(string)
200
+ Gem::Version.new(string)
201
+ end
202
+ end
203
+ end
204
204
  end