I'm trying to test a photo upload paperclip using Capybara. However I'm getting an error about file field when running cucumber test.
Unable to find file field :upload (Capybara::ElementNotFound)
Javascript
$("#uploadhere").click(function() {
$("#photo_upload_entry_upload").click();
});
Steps.rb file
Then(/^I should see photo when I upload and submit entry$/) do
script = "$('form.new_photo_upload_entry').css('i.fa.fa-file-image-o');"
page.execute_script(script)
fixture_path = Rails.root.join('spec', 'support', 'fixtures', 'test.jpg')
within('form.new_photo_upload_entry') do
attach_file(:upload, fixture_path)
end
end
HTML (using inspect element)
<input type="file" name="photo_upload_entry[upload]" id="photo_upload_entry_upload">
Ruby code of form in slim format
.entry-label STEP 1: UPLOAD YOUR IMAGE
.entry-upload#uploadhere
.upload-here
i.fa.fa-file-image-o
br
= "UPLOAD YOUR IMAGE HERE"
img
=f.file_field :upload
Unable to find file field "photo_upload_entry_upload" (Capybara::ElementNotFound)Unable to find file field "photo_upload_entry[upload]" (Capybara::ElementNotFound)