我正在尝试将PDF文件作为Rails测试套件的一部分进行测试。我有一个页面,其中有a#download_pdf
标识的PDF下载按钮。我想要做的是获取生成的文件并将其与存储的主文件进行比较。我不知道如何抓住这个文件。单击按钮后,我会弹出一个询问是否要保存或打开文件的弹出窗口。我该怎么办?!如何获取要保存的darn文件。
@page.find('a#download_pdf').click
这是我的 selenium_helper.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