module RspecExtensions::DownloadsHelpers

Constants

DOWNLOADS_PATH

Public Instance Methods

allow_file_downloads(page) click to toggle source
# File lib/rspec_tapas/downloads_helpers.rb, line 5
def allow_file_downloads(page)
  bridge = page.driver.browser.send(:bridge)
  path = '/session/:session_id/chromium/send_command'
  path[':session_id'] = bridge.session_id
  bridge.http.call(
    :post,
    path,
    cmd: 'Page.setDownloadBehavior',
    params: { behavior: 'allow', downloadPath: DOWNLOADS_PATH }
  )
end
downloaded_file_contents(name) click to toggle source
# File lib/rspec_tapas/downloads_helpers.rb, line 17
def downloaded_file_contents(name)
  read_attempt = 1

  begin
    File.read(Support::DownloadsHelpers::DOWNLOADS_PATH.join(name))
  rescue Errno::ENOENT => exception
    if read_attempt < 3
      read_attempt += 1
      sleep(Capybara.default_max_wait_time)
      retry
    else
      raise exception
    end
  end
end