【问题标题】:Capybara Button JS Response ActionController ErrorCapybara 按钮 JS 响应 ActionController 错误
【发布时间】:2018-10-02 12:09:17
【问题描述】:

我正在为我的项目编写一些测试并且遇到了一些问题。在测试中,我只是填写了一些字段,我想提交这个表格。它在浏览器中工作,但在测试中,我得到了formatError。这是错误:

ActionController::UnknownFormat: CompaniesController#update 缺少此请求格式和变体的模板。

request.formats: ["text/html"]
request.variant: []

小测试:

scenario 'update company with valid params' do
  visit company_account_information_path

  fill_in 'company_name', with: "Mustername für Firma"
  fill_in 'company_owner_name', with: "Mustermann"

  click_button "Speichern"
end

我还没有添加一些期望,因为它每次都失败了。

编辑:

是的,响应是js!它应该打开一个模式。

【问题讨论】:

    标签: ruby-on-rails testing ruby-on-rails-5 capybara


    【解决方案1】:

    要进行 js 测试,您需要在场景中指定 js: true,并且应该配置像 selenium 或 poltergeist 这样的 webdriver 来使用 capybara 执行 js。

    你的测试:

    scenario 'update company with valid params', js: true do
      visit company_account_information_path
    
      fill_in 'company_name', with: "Mustername für Firma"
      fill_in 'company_owner_name', with: "Mustermann"
    
      click_button "Speichern"
    end
    

    阅读这个文档来配置一个支持js的webdriver Capybara drivers

    【讨论】:

    • 完全正确 - OP 正在使用不支持 JS 的驱动程序运行需要 JS 的测试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    相关资源
    最近更新 更多