selenium_download_helper 1.1.0 → 1.2.1

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: aa84829d0e2102bcba993d16dfad54b041afb314f99a271e8f2575398d1ad413
4
- data.tar.gz: e4512c0f922cec27f3bfa779d8531a6cebdb95f1132caa5b74cce96891692ff6
3
+ metadata.gz: def57c20317984adb28e0c8172d28df8bb4e476725670ad5419da5220db6d8a0
4
+ data.tar.gz: 3c540b24dcbb3f3ad6deb2076dcd7bcce80369a86f94b5607a31079f601482e6
5
5
  SHA512:
6
- metadata.gz: 97a0da523c03be13c9fba644030934346382c2cbc78b7f927a14a2e359076188301249ef8589659faec89b7d4e54dbdc21cc70947a387ef8ad029031c8dd852e
7
- data.tar.gz: 6e3cd2dc07cfcc004803e3b08332321b0a064fdf648ec9e955f6c98e77f12c35604c936f29036f55e6cd51747c6da490ace90a9e2ef1c04556fa43e866e9ab45
6
+ metadata.gz: 165cdbdc81f4669786265d56cd9772d3ea1a53be066f14f1ecf902437f45fd880d42682651ee6fc3aa2e6cffa711dab2e6f761e68ab42190b53d96ca9657ceb8
7
+ data.tar.gz: 45290576fb05da2cdb4cfa14aa5c738253302fc2ec60362194de1445359a0db8aa5f3e638e82f8d49f25310b23046eebad4a642c8f08f20fc7322de64584ea95
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- selenium_download_helper (1.1.0)
4
+ selenium_download_helper (1.2.1)
5
5
  rails (>= 7.0)
6
6
  selenium-webdriver
7
7
 
@@ -119,12 +119,8 @@ GEM
119
119
  net-smtp (0.5.0)
120
120
  net-protocol
121
121
  nio4r (2.7.3)
122
- nokogiri (1.16.7)
123
- mini_portile2 (~> 2.8.2)
124
- racc (~> 1.4)
125
- nokogiri (1.16.7-arm64-darwin)
126
- racc (~> 1.4)
127
- nokogiri (1.16.7-x86_64-darwin)
122
+ nokogiri (1.14.3)
123
+ mini_portile2 (~> 2.8.0)
128
124
  racc (~> 1.4)
129
125
  psych (5.1.2)
130
126
  stringio
@@ -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.1.0'
4
+ VERSION = '1.2.1'
5
5
  end
@@ -5,10 +5,14 @@ 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)
@@ -21,6 +25,8 @@ module SeleniumDownloadHelper
21
25
  yield
22
26
  Selenium::WebDriver::Wait.new(timeout: timeout, interval: interval).until { downloaded?(download_path, filename:) }
23
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
@@ -37,11 +43,11 @@ module SeleniumDownloadHelper
37
43
  def downloaded_files(download_path, filename: nil)
38
44
  Dir[File.join(download_path, '*')]
39
45
  .map { |filepath| Pathname.new(filepath) }
46
+ .reject { |file| TEMPORARY_DOWNLOAD_FILENAME_PATTERN.match?(file.basename.to_s) }
40
47
  .select { |file| filename.nil? || filename === file.basename.to_s }
41
48
  end
42
49
 
43
50
  def downloaded?(download_path, filename: nil)
44
- files = downloaded_files(download_path, filename:)
45
- files.map(&:to_s).grep(/\.crdownload$/).none? && files.any?
51
+ downloaded_files(download_path, filename:).any?
46
52
  end
47
53
  end
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.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-22 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