module SeleniumDownloadHelper

Constants

VERSION

Public Instance Methods

wait_for_downloaded(timeout: 10, interval: 0.2, all: false) { || ... } click to toggle source
# File lib/selenium_download_helper.rb, line 18
def wait_for_downloaded(timeout: 10, interval: 0.2, all: false, &block)
  download_path= mkdownloaddir
  page.driver.browser.download_path = download_path
  yield
  Selenium::WebDriver::Wait.new(timeout: timeout, interval: interval).until { downloaded?(download_path) }
  downloaded_files(download_path).then { |files| all ? files : files.first }
end

Private Instance Methods

base_download_dir() click to toggle source
# File lib/selenium_download_helper.rb, line 28
def base_download_dir
  Rails.root.join('tmp/data/downloads')
end
downloaded?(download_path) click to toggle source
# File lib/selenium_download_helper.rb, line 41
def downloaded?(download_path)
  files = downloaded_files(download_path)
  files.map(&:to_s).grep(/\.crdownload$/).none? && files.any?
end
downloaded_files(download_path) click to toggle source
# File lib/selenium_download_helper.rb, line 37
def downloaded_files(download_path)
  Dir[File.join(download_path, '*')].map { |filepath| Pathname.new(filepath) }
end
mkdownloaddir() click to toggle source
# File lib/selenium_download_helper.rb, line 32
def mkdownloaddir
  FileUtils.mkdir_p(base_download_dir)
  Dir.mktmpdir('selenium_download_helper__', base_download_dir)
end