こんにちは私はrspec capybaraテストを実行しようとするといくつかの問題が発生し、レールの初心者です。Capybara :: ElementNotFound:ファイルフィールド "file"を見つけることができません
require 'rails_helper'
describe "Upload Process", :type => :feature do
it "Can upload a file" do
visit new_document_path
page.attach_file('file', '/Users/yaomin/Desktop/my_travel_pic/uploadtest.jpg', visible: false)
click_button 'Upload'
page.should have_content("Uploadtest")
end
end
しかし、私は私の見解コードは以下の
h1 Listing documents
table
thead
tr
th
th
th
tbody
- @documents.each do |document|
tr
td = link_to 'Show', document
td = link_to 'Edit', edit_document_path(document)
td = link_to 'Destroy', document, data: { confirm: 'Are you sure?' }, method: :delete
br
= link_to 'New Document', new_document_path
は、新しいドキュメントビューである
Failures:
1) Upload Process Can upload a file
Failure/Error: attach_file('file', '/Users/yaomin/Desktop/my_travel_pic/uploadtest.jpg', visible: false)
Capybara::ElementNotFound:
Unable to find file field "file"
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/node/finders.rb:44:in `block in find'
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/node/base.rb:85:in `synchronize'
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/node/finders.rb:33:in `find'
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/node/actions.rb:256:in `attach_file'
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/session.rb:769:in `block (2 levels) in <class:Session>'
# /Users/yaomin/.rvm/gems/ruby-2.3.1/gems/capybara-2.13.0/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
# ./spec/features/upload_test.rb:9:in `block (2 levels) in <top (required)>'
Finished in 0.40034 seconds (files took 1.99 seconds to load) 1 example, 1 failure
Failed examples:
rspec ./spec/features/upload_test.rb:5 # Upload Process Can upload a file
エラーを得た
h1 New document
= render 'form'
= link_to 'Back', documents_path
- if @document.folder
= link_to "Back to '#{@document.folder.name}' Folder", browse_path(@document.folder)
- else
= link_to "Back", root_url
と
部分私のフォーム3210= form_for @document do |f|
- if @document.errors.any?
#error_explanation
h2 = "#{pluralize(@document.errors.count, "error")} prohibited this document from being saved:"
ul
- @document.errors.full_messages.each do |message|
li = message
= f.label :file
= f.file_field :file
- f.hidden_field :folder_id
= f.submit "Upload"
実際にはファイルを手動でアップロードできますが、アップロードテストは失敗します。すべてのあなたの助けを事前に
感謝:)
あなたのビューコードを教えてください。そして 'ファイルをアップロードできます'の中で 'save_and_open_page'を実行すると、実際のファイルフィールドが見えますか? –
ビューと部分形式で更新 – NYM
保存して開いているページがうまく動作します – NYM