Ruby on rails 如何使用selenium&;测试PDF下载;红宝石水豚

Ruby on rails 如何使用selenium&;测试PDF下载;红宝石水豚,ruby-on-rails,pdf,selenium,capybara,Ruby On Rails,Pdf,Selenium,Capybara,我正在尝试将PDF文件作为Rails测试套件的一部分进行测试。我有一个页面有一个PDF下载按钮,由a#download_PDF标识。我要做的是获取生成的文件,并将其与存储的主文件进行比较。但是我不知道如何抓取这个文件。一旦我点击按钮,我会弹出询问我是否要保存或打开文件。我该怎么办?!我怎样才能把那个该死的文件保存下来 @page.find('a#download_pdf').click 这是我的硒助手.rb require_relative 'test_helper' require 'dat

我正在尝试将PDF文件作为Rails测试套件的一部分进行测试。我有一个页面有一个PDF下载按钮,由
a#download_PDF
标识。我要做的是获取生成的文件,并将其与存储的主文件进行比较。但是我不知道如何抓取这个文件。一旦我点击按钮,我会弹出询问我是否要保存或打开文件。我该怎么办?!我怎样才能把那个该死的文件保存下来

@page.find('a#download_pdf').click
这是我的硒助手.rb

require_relative 'test_helper'
require 'database_cleaner'

ENV["RAILS_ENV"] = "test"

# Because of the use of mixins, the order of loading matters
require File.dirname(__FILE__) + '/integration/page_objects/page_object.rb'

Dir[File.dirname(__FILE__) + '/integration/page_objects/mixins/*.rb'].each do |page_object|
  require page_object
end

Dir[File.dirname(__FILE__) + '/integration/page_objects/*/*.rb'].each do |page_object|
  require page_object
end

module MyApp
  class SeleniumIntegrationTest < ActionDispatch::IntegrationTest
    include Capybara::DSL
    include Warden::Test::Helpers
    DatabaseCleaner.strategy = :truncation
    Capybara.current_driver = :selenium
    fixtures :all
    self.use_transactional_fixtures = false

    setup do
      DatabaseCleaner.start

      # Stub out Recurly methods
      Recurly::Account.stubs(:find)

      # We need to make the size of the browser bigger.  Otherwise Capybara
      # can't find elements when a form goes below the bottom of the browser.
      page.driver.browser.manage.window.resize_to(1200,800)
    end

    ...
  end   
end
require\u relative“test\u helper”
需要“数据库清理器”
环境[“RAILS_ENV”]=“测试”
#由于使用了混合器,装载顺序很重要
require File.dirname(_File__;)+'/integration/page_objects/page_object.rb'
Dir[File.dirname(+/integration/page_objects/mixins/*.rb']。每个do都是page_对象|
需要页面\u对象
结束
Dir[File.dirname(+/integration/page_objects/*/*.rb']。每个do都是page_对象|
需要页面\u对象
结束
模块MyApp
类SeleniumIntegrationTest