webdrivers 3.9.2 → 3.9.3

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,61 +1,61 @@
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
+ # 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,154 +1,154 @@
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
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