Module: RspecExtensions::DownloadsHelpers

Defined in:
lib/rspec_tapas/downloads_helpers.rb

Constant Summary collapse

DOWNLOADS_PATH =
Rails.root.join('tmp').freeze

Instance Method Summary collapse

Instance Method Details

#allow_file_downloads(page) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# 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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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