【问题标题】:Capybara fails with NotSupportedByDriverErrorCapybara 因 NotSupportedByDriverError 而失败
【发布时间】:2019-08-30 05:38:42
【问题描述】:

我正在尝试在我的 rails 应用程序中验证下载 csv 是否有效。但它抛出错误Capybara::NotSupportedByDriverError: Capybara::Driver::Base#response_headers

  it 'exports as CSV' do
    visit_and_login
    agree_to_tos

    click_link 'Download to CSV'

    page.response_headers['Content-Type'].should include 'text/csv'
  end

【问题讨论】:

    标签: ruby rspec capybara ruby-on-rails-5.2


    【解决方案1】:

    selenium 驱动程序不提供对响应标头(也不提供状态代码)的访问。你有几个选择

    1. 只需验证 href 和属性(下载等)或链接是否正确
    2. 将驱动程序配置为实际下载文件,然后打开并验证它是否正确。

    阅读http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html,然后决定你想做什么。如果是#1,那么它很简单

    expect(page).to have_link('Download to CSV', href: 'http://blahblah' )
    

    如果 #2 则查看 Capybara 测试套件,了解如何配置 selenium 驱动程序以实际下载文件 - https://github.com/teamcapybara/capybara/blob/master/spec/selenium_spec_chrome.rb#L14

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 2018-02-16
      • 2017-12-12
      • 2012-10-03
      • 2014-07-16
      • 2021-11-23
      • 2018-10-04
      相关资源
      最近更新 更多