selenium_download_helper 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85e717fb652e52a196fe55a4cc971559ea40ca19520697224a61954314a2ccd6
4
- data.tar.gz: 751c36041230552bc4c8e0a0ef461319be336a561fd91d5530c4054c2afed474
3
+ metadata.gz: 5467dad132759192c6e70376b7c2f7cf5432acdaa1c7448026c28eb64251b7e9
4
+ data.tar.gz: 5380c0df4b66f7643fc118f7e69be0384651e1c98fc934189967a8317ca61439
5
5
  SHA512:
6
- metadata.gz: 0ee99f51e617dd311131a3fb5a23d1d05418aaeea6739ac99570c722a9d1de8f850b5dae188f2425bf459300c0a641a384dc184f0cf3a00962e6a804ccc6d8a4
7
- data.tar.gz: 47f6086b1363285424b4951c88ee1995b971c511f7fa942706271aa53bc66e8499cae5bf231f848b4d17d78d2acaf9f3d7be80268bb17ab3878d0c60a1987239
6
+ metadata.gz: d50cafa8b05cb778c76f7d3d727cb8a42bb3bceb6e234f6450001e5d9e8389a41574e34c5e8bf01232d80f26befa595e96d6b99dd52d61b62c7fc4cf6de11d43
7
+ data.tar.gz: c76971e08269761e80b6a33b5dc51787328a6678c83f79906405992121d655c7e3846c01756ac8ff73d5528031aece3cb9b9b4471e78208a9dfeb4b94250e1f8
data/Gemfile.lock CHANGED
@@ -1,91 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- selenium_download_helper (1.0.0)
4
+ selenium_download_helper (1.2.0)
5
5
  rails (>= 7.0)
6
6
  selenium-webdriver
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.1.3.4)
12
- actionpack (= 7.1.3.4)
13
- activesupport (= 7.1.3.4)
11
+ actioncable (7.2.1)
12
+ actionpack (= 7.2.1)
13
+ activesupport (= 7.2.1)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
16
  zeitwerk (~> 2.6)
17
- actionmailbox (7.1.3.4)
18
- actionpack (= 7.1.3.4)
19
- activejob (= 7.1.3.4)
20
- activerecord (= 7.1.3.4)
21
- activestorage (= 7.1.3.4)
22
- activesupport (= 7.1.3.4)
23
- mail (>= 2.7.1)
24
- net-imap
25
- net-pop
26
- net-smtp
27
- actionmailer (7.1.3.4)
28
- actionpack (= 7.1.3.4)
29
- actionview (= 7.1.3.4)
30
- activejob (= 7.1.3.4)
31
- activesupport (= 7.1.3.4)
32
- mail (~> 2.5, >= 2.5.4)
33
- net-imap
34
- net-pop
35
- net-smtp
17
+ actionmailbox (7.2.1)
18
+ actionpack (= 7.2.1)
19
+ activejob (= 7.2.1)
20
+ activerecord (= 7.2.1)
21
+ activestorage (= 7.2.1)
22
+ activesupport (= 7.2.1)
23
+ mail (>= 2.8.0)
24
+ actionmailer (7.2.1)
25
+ actionpack (= 7.2.1)
26
+ actionview (= 7.2.1)
27
+ activejob (= 7.2.1)
28
+ activesupport (= 7.2.1)
29
+ mail (>= 2.8.0)
36
30
  rails-dom-testing (~> 2.2)
37
- actionpack (7.1.3.4)
38
- actionview (= 7.1.3.4)
39
- activesupport (= 7.1.3.4)
31
+ actionpack (7.2.1)
32
+ actionview (= 7.2.1)
33
+ activesupport (= 7.2.1)
40
34
  nokogiri (>= 1.8.5)
41
35
  racc
42
- rack (>= 2.2.4)
36
+ rack (>= 2.2.4, < 3.2)
43
37
  rack-session (>= 1.0.1)
44
38
  rack-test (>= 0.6.3)
45
39
  rails-dom-testing (~> 2.2)
46
40
  rails-html-sanitizer (~> 1.6)
47
- actiontext (7.1.3.4)
48
- actionpack (= 7.1.3.4)
49
- activerecord (= 7.1.3.4)
50
- activestorage (= 7.1.3.4)
51
- activesupport (= 7.1.3.4)
41
+ useragent (~> 0.16)
42
+ actiontext (7.2.1)
43
+ actionpack (= 7.2.1)
44
+ activerecord (= 7.2.1)
45
+ activestorage (= 7.2.1)
46
+ activesupport (= 7.2.1)
52
47
  globalid (>= 0.6.0)
53
48
  nokogiri (>= 1.8.5)
54
- actionview (7.1.3.4)
55
- activesupport (= 7.1.3.4)
49
+ actionview (7.2.1)
50
+ activesupport (= 7.2.1)
56
51
  builder (~> 3.1)
57
52
  erubi (~> 1.11)
58
53
  rails-dom-testing (~> 2.2)
59
54
  rails-html-sanitizer (~> 1.6)
60
- activejob (7.1.3.4)
61
- activesupport (= 7.1.3.4)
55
+ activejob (7.2.1)
56
+ activesupport (= 7.2.1)
62
57
  globalid (>= 0.3.6)
63
- activemodel (7.1.3.4)
64
- activesupport (= 7.1.3.4)
65
- activerecord (7.1.3.4)
66
- activemodel (= 7.1.3.4)
67
- activesupport (= 7.1.3.4)
58
+ activemodel (7.2.1)
59
+ activesupport (= 7.2.1)
60
+ activerecord (7.2.1)
61
+ activemodel (= 7.2.1)
62
+ activesupport (= 7.2.1)
68
63
  timeout (>= 0.4.0)
69
- activestorage (7.1.3.4)
70
- actionpack (= 7.1.3.4)
71
- activejob (= 7.1.3.4)
72
- activerecord (= 7.1.3.4)
73
- activesupport (= 7.1.3.4)
64
+ activestorage (7.2.1)
65
+ actionpack (= 7.2.1)
66
+ activejob (= 7.2.1)
67
+ activerecord (= 7.2.1)
68
+ activesupport (= 7.2.1)
74
69
  marcel (~> 1.0)
75
- activesupport (7.1.3.4)
70
+ activesupport (7.2.1)
76
71
  base64
77
72
  bigdecimal
78
- concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
79
74
  connection_pool (>= 2.2.5)
80
75
  drb
81
76
  i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
82
78
  minitest (>= 5.1)
83
- mutex_m
84
- tzinfo (~> 2.0)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
85
81
  base64 (0.2.0)
86
82
  bigdecimal (3.1.8)
87
83
  builder (3.3.0)
88
- concurrent-ruby (1.3.3)
84
+ concurrent-ruby (1.3.4)
89
85
  connection_pool (2.4.1)
90
86
  crass (1.0.6)
91
87
  date (3.3.4)
@@ -112,8 +108,7 @@ GEM
112
108
  marcel (1.0.4)
113
109
  mini_mime (1.1.5)
114
110
  mini_portile2 (2.8.7)
115
- minitest (5.24.1)
116
- mutex_m (0.2.0)
111
+ minitest (5.25.1)
117
112
  net-imap (0.4.14)
118
113
  date
119
114
  net-protocol
@@ -124,16 +119,12 @@ GEM
124
119
  net-smtp (0.5.0)
125
120
  net-protocol
126
121
  nio4r (2.7.3)
127
- nokogiri (1.16.6)
128
- mini_portile2 (~> 2.8.2)
129
- racc (~> 1.4)
130
- nokogiri (1.16.6-arm64-darwin)
131
- racc (~> 1.4)
132
- nokogiri (1.16.6-x86_64-darwin)
122
+ nokogiri (1.14.3)
123
+ mini_portile2 (~> 2.8.0)
133
124
  racc (~> 1.4)
134
125
  psych (5.1.2)
135
126
  stringio
136
- racc (1.8.0)
127
+ racc (1.8.1)
137
128
  rack (3.1.7)
138
129
  rack-session (2.0.0)
139
130
  rack (>= 3.0.0)
@@ -142,20 +133,20 @@ GEM
142
133
  rackup (2.1.0)
143
134
  rack (>= 3)
144
135
  webrick (~> 1.8)
145
- rails (7.1.3.4)
146
- actioncable (= 7.1.3.4)
147
- actionmailbox (= 7.1.3.4)
148
- actionmailer (= 7.1.3.4)
149
- actionpack (= 7.1.3.4)
150
- actiontext (= 7.1.3.4)
151
- actionview (= 7.1.3.4)
152
- activejob (= 7.1.3.4)
153
- activemodel (= 7.1.3.4)
154
- activerecord (= 7.1.3.4)
155
- activestorage (= 7.1.3.4)
156
- activesupport (= 7.1.3.4)
136
+ rails (7.2.1)
137
+ actioncable (= 7.2.1)
138
+ actionmailbox (= 7.2.1)
139
+ actionmailer (= 7.2.1)
140
+ actionpack (= 7.2.1)
141
+ actiontext (= 7.2.1)
142
+ actionview (= 7.2.1)
143
+ activejob (= 7.2.1)
144
+ activemodel (= 7.2.1)
145
+ activerecord (= 7.2.1)
146
+ activestorage (= 7.2.1)
147
+ activesupport (= 7.2.1)
157
148
  bundler (>= 1.15.0)
158
- railties (= 7.1.3.4)
149
+ railties (= 7.2.1)
159
150
  rails-dom-testing (2.2.0)
160
151
  activesupport (>= 5.0.0)
161
152
  minitest
@@ -163,10 +154,10 @@ GEM
163
154
  rails-html-sanitizer (1.6.0)
164
155
  loofah (~> 2.21)
165
156
  nokogiri (~> 1.14)
166
- railties (7.1.3.4)
167
- actionpack (= 7.1.3.4)
168
- activesupport (= 7.1.3.4)
169
- irb
157
+ railties (7.2.1)
158
+ actionpack (= 7.2.1)
159
+ activesupport (= 7.2.1)
160
+ irb (~> 1.13)
170
161
  rackup (>= 1.0.0)
171
162
  rake (>= 12.2)
172
163
  thor (~> 1.0, >= 1.2.2)
@@ -176,7 +167,7 @@ GEM
176
167
  psych (>= 4.0.0)
177
168
  reline (0.5.9)
178
169
  io-console (~> 0.5)
179
- rexml (3.3.2)
170
+ rexml (3.3.6)
180
171
  strscan
181
172
  rspec (3.10.0)
182
173
  rspec-core (~> 3.10.0)
@@ -192,6 +183,7 @@ GEM
192
183
  rspec-support (~> 3.10.0)
193
184
  rspec-support (3.10.2)
194
185
  rubyzip (2.3.2)
186
+ securerandom (0.3.1)
195
187
  selenium-webdriver (4.23.0)
196
188
  base64 (~> 0.2)
197
189
  logger (~> 1.4)
@@ -204,12 +196,13 @@ GEM
204
196
  timeout (0.4.1)
205
197
  tzinfo (2.0.6)
206
198
  concurrent-ruby (~> 1.0)
199
+ useragent (0.16.10)
207
200
  webrick (1.8.1)
208
201
  websocket (1.2.11)
209
202
  websocket-driver (0.7.6)
210
203
  websocket-extensions (>= 0.1.0)
211
204
  websocket-extensions (0.1.5)
212
- zeitwerk (2.6.16)
205
+ zeitwerk (2.6.17)
213
206
 
214
207
  PLATFORMS
215
208
  arm64-darwin-22
@@ -0,0 +1,12 @@
1
+ module SeleniumDownloadHelper
2
+ class TimeoutError < StandardError
3
+ def initialize(error, download_path)
4
+ @download_path = download_path
5
+ super("#{error.message}\nDownloaded files:\n#{downloaded_files.join("\n")}")
6
+ end
7
+
8
+ def downloaded_files
9
+ Dir[File.join(@download_path, '*')]
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SeleniumDownloadHelper
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -5,22 +5,28 @@ require 'fileutils'
5
5
  require 'selenium-webdriver'
6
6
  require 'active_support/concern'
7
7
  require_relative 'selenium_download_helper/version'
8
+ require_relative 'selenium_download_helper/errors'
8
9
 
9
10
  module SeleniumDownloadHelper
10
11
  extend ActiveSupport::Concern
11
12
 
13
+ TEMPORARY_DOWNLOAD_FILENAME_PATTERN = /(\.crdownload|\/downloads.html)$/
14
+
15
+
12
16
  included do
13
17
  after(:all) do
14
18
  FileUtils.rm_rf(base_download_dir)
15
19
  end
16
20
  end
17
21
 
18
- def wait_for_downloaded(timeout: 10, interval: 0.2, all: false, &block)
22
+ def wait_for_downloaded(timeout: 10, interval: 0.2, all: false, filename: nil, &block)
19
23
  download_path= mkdownloaddir
20
24
  page.driver.browser.download_path = download_path
21
25
  yield
22
- Selenium::WebDriver::Wait.new(timeout: timeout, interval: interval).until { downloaded?(download_path) }
23
- downloaded_files(download_path).then { |files| all ? files : files.first }
26
+ Selenium::WebDriver::Wait.new(timeout: timeout, interval: interval).until { downloaded?(download_path, filename:) }
27
+ downloaded_files(download_path, filename:).then { |files| all ? files : files.first }
28
+ rescue Selenium::WebDriver::Error::TimeoutError => e
29
+ raise TimeoutError.new(e, download_path)
24
30
  end
25
31
 
26
32
  private
@@ -34,12 +40,14 @@ module SeleniumDownloadHelper
34
40
  Dir.mktmpdir('selenium_download_helper__', base_download_dir)
35
41
  end
36
42
 
37
- def downloaded_files(download_path)
38
- Dir[File.join(download_path, '*')].map { |filepath| Pathname.new(filepath) }
43
+ def downloaded_files(download_path, filename: nil)
44
+ Dir[File.join(download_path, '*')]
45
+ .map { |filepath| Pathname.new(filepath) }
46
+ .select { |file| filename.nil? || filename === file.basename.to_s }
39
47
  end
40
48
 
41
- def downloaded?(download_path)
42
- files = downloaded_files(download_path)
43
- files.map(&:to_s).grep(/\.crdownload$/).none? && files.any?
49
+ def downloaded?(download_path, filename: nil)
50
+ files = downloaded_files(download_path, filename:)
51
+ files.map(&:to_s).grep(TEMPORARY_DOWNLOAD_FILENAME_PATTERN).none? && files.any?
44
52
  end
45
53
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "https://github.com/SonicGarden/selenium_download_helper/blob/master/CHANGELOG.md"
19
+ spec.metadata["changelog_uri"] = "https://github.com/SonicGarden/selenium_download_helper/releases"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium_download_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,6 +58,7 @@ files:
58
58
  - bin/console
59
59
  - bin/setup
60
60
  - lib/selenium_download_helper.rb
61
+ - lib/selenium_download_helper/errors.rb
61
62
  - lib/selenium_download_helper/version.rb
62
63
  - selenium_download_helper.gemspec
63
64
  homepage: https://github.com/SonicGarden/selenium_download_helper
@@ -66,7 +67,7 @@ licenses:
66
67
  metadata:
67
68
  homepage_uri: https://github.com/SonicGarden/selenium_download_helper
68
69
  source_code_uri: https://github.com/SonicGarden/selenium_download_helper
69
- changelog_uri: https://github.com/SonicGarden/selenium_download_helper/blob/master/CHANGELOG.md
70
+ changelog_uri: https://github.com/SonicGarden/selenium_download_helper/releases
70
71
  post_install_message:
71
72
  rdoc_options: []
72
73
  require_paths: