webdrivers 3.9.1 → 3.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,55 +1,55 @@
1
- # frozen_string_literal: true
2
-
3
- require 'webdrivers/common'
4
-
5
- module Webdrivers
6
- class MSWebdriver
7
- class << self
8
- attr_accessor :ignore
9
- end
10
- end
11
- end
12
-
13
- module Selenium
14
- module WebDriver
15
- module Edge
16
- if defined?(Selenium::WebDriver::VERSION) && Selenium::WebDriver::VERSION > '3.141.0'
17
- class Service < WebDriver::Service
18
- class << self
19
- alias se_driver_path driver_path
20
-
21
- def driver_path
22
- unless Webdrivers::MSWebdriver.ignore
23
- Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
24
- ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
25
- 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
26
- 'or place it in PATH Environment Variable. '\
27
- 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
28
- 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
29
- end
30
-
31
- se_driver_path
32
- end
33
- end
34
- end
35
- else
36
- class << self
37
- alias se_driver_path driver_path
38
-
39
- def driver_path
40
- unless Webdrivers::MSWebdriver.ignore
41
- Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
42
- ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
43
- 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
44
- 'or place it in PATH Environment Variable. '\
45
- 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
46
- 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
47
- end
48
-
49
- se_driver_path
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'webdrivers/common'
4
+
5
+ module Webdrivers
6
+ class MSWebdriver
7
+ class << self
8
+ attr_accessor :ignore
9
+ end
10
+ end
11
+ end
12
+
13
+ module Selenium
14
+ module WebDriver
15
+ module Edge
16
+ if defined?(Selenium::WebDriver::VERSION) && Selenium::WebDriver::VERSION > '3.141.0'
17
+ class Service < WebDriver::Service
18
+ class << self
19
+ alias se_driver_path driver_path
20
+
21
+ def driver_path
22
+ unless Webdrivers::MSWebdriver.ignore
23
+ Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
24
+ ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
25
+ 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
26
+ 'or place it in PATH Environment Variable. '\
27
+ 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
28
+ 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
29
+ end
30
+
31
+ se_driver_path
32
+ end
33
+ end
34
+ end
35
+ else
36
+ class << self
37
+ alias se_driver_path driver_path
38
+
39
+ def driver_path
40
+ unless Webdrivers::MSWebdriver.ignore
41
+ Webdrivers.logger.warn 'Microsoft WebDriver for the Edge browser is no longer supported by Webdrivers'\
42
+ ' gem. Due to changes in Edge implementation, the correct version can no longer be accurately provided. '\
43
+ 'Download driver, and specify the location with `Selenium::WebDriver::Edge.driver_path = "/driver/path"`, '\
44
+ 'or place it in PATH Environment Variable. '\
45
+ 'Download directions here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads '\
46
+ 'To remove this warning in Webdrivers 3.x, set `Webdrivers.MSWebdriver.ignore`'
47
+ end
48
+
49
+ se_driver_path
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,58 +1,61 @@
1
- # frozen_string_literal: true
2
-
3
- module Webdrivers
4
- class Network
5
- class << self
6
- def get(url, limit = 10)
7
- Webdrivers.logger.debug "Making network call to #{url}"
8
-
9
- response = get_response(url, limit)
10
- case response
11
- when Net::HTTPSuccess
12
- response.body
13
- else
14
- raise StandardError, "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}"
15
- end
16
- end
17
-
18
- def get_url(url, limit = 10)
19
- Webdrivers.logger.debug "Making network call to #{url}"
20
-
21
- get_response(url, limit).uri.to_s
22
- end
23
-
24
- def get_response(url, limit = 10)
25
- raise StandardError, 'Too many HTTP redirects' if limit.zero?
26
-
27
- begin
28
- response = http.get_response(URI(url))
29
- rescue SocketError
30
- raise ConnectionError, "Can not reach #{url}"
31
- end
32
-
33
- Webdrivers.logger.debug "Get response: #{response.inspect}"
34
-
35
- if response.is_a?(Net::HTTPRedirection)
36
- location = response['location']
37
- Webdrivers.logger.debug "Redirected to #{location}"
38
- get_response(location, limit - 1)
39
- else
40
- response
41
- end
42
- end
43
-
44
- def http
45
- if using_proxy
46
- Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
47
- Webdrivers.proxy_user, Webdrivers.proxy_pass)
48
- else
49
- Net::HTTP
50
- end
51
- end
52
-
53
- def using_proxy
54
- Webdrivers.proxy_addr && Webdrivers.proxy_port
55
- end
56
- end
57
- end
58
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Webdrivers
4
+ #
5
+ # @api private
6
+ #
7
+ class Network
8
+ class << self
9
+ def get(url, limit = 10)
10
+ Webdrivers.logger.debug "Making network call to #{url}"
11
+
12
+ response = get_response(url, limit)
13
+ case response
14
+ when Net::HTTPSuccess
15
+ response.body
16
+ else
17
+ raise NetworkError, "#{response.class::EXCEPTION_TYPE}: #{response.code} \"#{response.message}\" with #{url}"
18
+ end
19
+ end
20
+
21
+ def get_url(url, limit = 10)
22
+ Webdrivers.logger.debug "Making network call to #{url}"
23
+
24
+ get_response(url, limit).uri.to_s
25
+ end
26
+
27
+ def get_response(url, limit = 10)
28
+ raise ConnectionError, 'Too many HTTP redirects' if limit.zero?
29
+
30
+ begin
31
+ response = http.get_response(URI(url))
32
+ rescue SocketError
33
+ raise ConnectionError, "Can not reach #{url}"
34
+ end
35
+
36
+ Webdrivers.logger.debug "Get response: #{response.inspect}"
37
+
38
+ if response.is_a?(Net::HTTPRedirection)
39
+ location = response['location']
40
+ Webdrivers.logger.debug "Redirected to #{location}"
41
+ get_response(location, limit - 1)
42
+ else
43
+ response
44
+ end
45
+ end
46
+
47
+ def http
48
+ if using_proxy
49
+ Net::HTTP.Proxy(Webdrivers.proxy_addr, Webdrivers.proxy_port,
50
+ Webdrivers.proxy_user, Webdrivers.proxy_pass)
51
+ else
52
+ Net::HTTP
53
+ end
54
+ end
55
+
56
+ def using_proxy
57
+ Webdrivers.proxy_addr && Webdrivers.proxy_port
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,151 +1,154 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems/package'
4
- require 'zip'
5
-
6
- module Webdrivers
7
- class System
8
- class << self
9
- def delete(file)
10
- max_attempts = 3
11
- attempts_made = 0
12
- delay = 0.5
13
- Webdrivers.logger.debug "Deleting #{file}"
14
-
15
- begin
16
- attempts_made += 1
17
- File.delete file if File.exist? file
18
- rescue Errno::EACCES # Solves an intermittent file locking issue on Windows
19
- sleep(delay)
20
- retry if File.exist?(file) && attempts_made <= max_attempts
21
- raise
22
- end
23
- end
24
-
25
- def install_dir
26
- Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
27
- end
28
-
29
- def cache_version(file_name, version)
30
- FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
31
-
32
- File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'w+') do |file|
33
- file.print(version)
34
- end
35
- end
36
-
37
- def cached_version(file_name)
38
- File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'r', &:read)
39
- end
40
-
41
- def valid_cache?(file_name)
42
- file = "#{install_dir}/#{file_name.gsub('.exe', '')}.version"
43
- return false unless File.exist?(file)
44
-
45
- Time.now - File.mtime(file) < Webdrivers.cache_time
46
- end
47
-
48
- def download(url, target)
49
- FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
50
-
51
- download_file(url, target)
52
-
53
- FileUtils.chmod 'ugo+rx', target
54
- Webdrivers.logger.debug "Completed download and processing of #{target}"
55
- target
56
- end
57
-
58
- def download_file(url, target)
59
- file_name = File.basename(url)
60
- Dir.chdir(install_dir) do
61
- tempfile = Tempfile.open(['', file_name], binmode: true) do |file|
62
- file.print Network.get(url)
63
- file
64
- end
65
-
66
- raise "Could not download #{url}" unless File.exist?(tempfile.to_path)
67
-
68
- Webdrivers.logger.debug "Successfully downloaded #{tempfile.to_path}"
69
-
70
- decompress_file(tempfile, file_name, target)
71
- tempfile.close!
72
- end
73
- end
74
-
75
- def exists?(file)
76
- result = File.exist? file
77
- Webdrivers.logger.debug "#{file} is#{' not' unless result} already downloaded"
78
- result
79
- end
80
-
81
- def decompress_file(tempfile, file_name, target)
82
- tempfile = tempfile.to_path
83
- case tempfile
84
- when /tar\.gz$/
85
- untargz_file(tempfile, File.basename(target))
86
- when /tar\.bz2$/
87
- untarbz2_file(tempfile)
88
- when /\.zip$/
89
- unzip_file(tempfile)
90
- else
91
- Webdrivers.logger.debug 'No Decompression needed'
92
- FileUtils.cp(tempfile, File.join(Dir.pwd, file_name))
93
- end
94
- raise "Could not decompress #{url} to get #{target}" unless File.exist?(target)
95
- end
96
-
97
- def untarbz2_file(filename)
98
- Webdrivers.logger.debug "Decompressing #{filename}"
99
-
100
- call("tar xjf #{filename}").gsub('.tar.bz2', '')
101
- end
102
-
103
- def untargz_file(source, target)
104
- Webdrivers.logger.debug "Decompressing #{source}"
105
-
106
- tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source))
107
-
108
- File.open(target, 'w+b') do |ucf|
109
- tar_extract.each { |entry| ucf << entry.read }
110
- File.basename ucf
111
- end
112
- end
113
-
114
- def unzip_file(filename)
115
- Webdrivers.logger.debug "Decompressing #{filename}"
116
-
117
- Zip::File.open(filename) do |zip_file|
118
- zip_file.each do |f|
119
- @top_path ||= f.name
120
- f_path = File.join(Dir.pwd, f.name)
121
- delete(f_path)
122
- FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
123
- zip_file.extract(f, f_path)
124
- end
125
- end
126
- @top_path
127
- end
128
-
129
- def platform
130
- if Selenium::WebDriver::Platform.linux?
131
- 'linux'
132
- elsif Selenium::WebDriver::Platform.mac?
133
- 'mac'
134
- elsif Selenium::WebDriver::Platform.windows?
135
- 'win'
136
- else
137
- raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
138
- end
139
- end
140
-
141
- def bitsize
142
- Selenium::WebDriver::Platform.bitsize
143
- end
144
-
145
- def call(cmd)
146
- Webdrivers.logger.debug "making System call: #{cmd}"
147
- `#{cmd}`
148
- end
149
- end
150
- end
151
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems/package'
4
+ require 'zip'
5
+
6
+ module Webdrivers
7
+ #
8
+ # @api private
9
+ #
10
+ class System
11
+ class << self
12
+ def delete(file)
13
+ max_attempts = 3
14
+ attempts_made = 0
15
+ delay = 0.5
16
+ Webdrivers.logger.debug "Deleting #{file}"
17
+
18
+ begin
19
+ attempts_made += 1
20
+ File.delete file if File.exist? file
21
+ rescue Errno::EACCES # Solves an intermittent file locking issue on Windows
22
+ sleep(delay)
23
+ retry if File.exist?(file) && attempts_made <= max_attempts
24
+ raise
25
+ end
26
+ end
27
+
28
+ def install_dir
29
+ Webdrivers.install_dir || File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
30
+ end
31
+
32
+ def cache_version(file_name, version)
33
+ FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
34
+
35
+ File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'w+') do |file|
36
+ file.print(version)
37
+ end
38
+ end
39
+
40
+ def cached_version(file_name)
41
+ File.open("#{install_dir}/#{file_name.gsub('.exe', '')}.version", 'r', &:read)
42
+ end
43
+
44
+ def valid_cache?(file_name)
45
+ file = "#{install_dir}/#{file_name.gsub('.exe', '')}.version"
46
+ return false unless File.exist?(file)
47
+
48
+ Time.now - File.mtime(file) < Webdrivers.cache_time
49
+ end
50
+
51
+ def download(url, target)
52
+ FileUtils.mkdir_p(install_dir) unless File.exist?(install_dir)
53
+
54
+ download_file(url, target)
55
+
56
+ FileUtils.chmod 'ugo+rx', target
57
+ Webdrivers.logger.debug "Completed download and processing of #{target}"
58
+ target
59
+ end
60
+
61
+ def download_file(url, target)
62
+ file_name = File.basename(url)
63
+ Dir.chdir(install_dir) do
64
+ tempfile = Tempfile.open(['', file_name], binmode: true) do |file|
65
+ file.print Network.get(url)
66
+ file
67
+ end
68
+
69
+ raise "Could not download #{url}" unless File.exist?(tempfile.to_path)
70
+
71
+ Webdrivers.logger.debug "Successfully downloaded #{tempfile.to_path}"
72
+
73
+ decompress_file(tempfile, file_name, target)
74
+ tempfile.close!
75
+ end
76
+ end
77
+
78
+ def exists?(file)
79
+ result = File.exist? file
80
+ Webdrivers.logger.debug "#{file} is#{' not' unless result} already downloaded"
81
+ result
82
+ end
83
+
84
+ def decompress_file(tempfile, file_name, target)
85
+ tempfile = tempfile.to_path
86
+ case tempfile
87
+ when /tar\.gz$/
88
+ untargz_file(tempfile, File.basename(target))
89
+ when /tar\.bz2$/
90
+ untarbz2_file(tempfile)
91
+ when /\.zip$/
92
+ unzip_file(tempfile)
93
+ else
94
+ Webdrivers.logger.debug 'No Decompression needed'
95
+ FileUtils.cp(tempfile, File.join(Dir.pwd, file_name))
96
+ end
97
+ raise "Could not decompress #{file_name} to get #{target}" unless File.exist?(File.basename(target))
98
+ end
99
+
100
+ def untarbz2_file(filename)
101
+ Webdrivers.logger.debug "Decompressing #{filename}"
102
+
103
+ call("tar xjf #{filename}").gsub('.tar.bz2', '')
104
+ end
105
+
106
+ def untargz_file(source, target)
107
+ Webdrivers.logger.debug "Decompressing #{source}"
108
+
109
+ tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source))
110
+
111
+ File.open(target, 'w+b') do |ucf|
112
+ tar_extract.each { |entry| ucf << entry.read }
113
+ File.basename ucf
114
+ end
115
+ end
116
+
117
+ def unzip_file(filename)
118
+ Webdrivers.logger.debug "Decompressing #{filename}"
119
+
120
+ Zip::File.open(filename) do |zip_file|
121
+ zip_file.each do |f|
122
+ @top_path ||= f.name
123
+ f_path = File.join(Dir.pwd, f.name)
124
+ delete(f_path)
125
+ FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
126
+ zip_file.extract(f, f_path)
127
+ end
128
+ end
129
+ @top_path
130
+ end
131
+
132
+ def platform
133
+ if Selenium::WebDriver::Platform.linux?
134
+ 'linux'
135
+ elsif Selenium::WebDriver::Platform.mac?
136
+ 'mac'
137
+ elsif Selenium::WebDriver::Platform.windows?
138
+ 'win'
139
+ else
140
+ raise NotImplementedError, 'Your OS is not supported by webdrivers gem.'
141
+ end
142
+ end
143
+
144
+ def bitsize
145
+ Selenium::WebDriver::Platform.bitsize
146
+ end
147
+
148
+ def call(cmd)
149
+ Webdrivers.logger.debug "making System call: #{cmd}"
150
+ `#{cmd}`
151
+ end
152
+ end
153
+ end
154
+ end