如何使用selenium&amp ;;测试PDF下载红宝石中的水豚

时间:2014-11-07 20:06:26

标签: ruby-on-rails pdf selenium capybara

我正在尝试将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

0 个答案:

没有答案