I want to do Image upload test(feature spec)












0















I want to test Image uploader.



My error is



Failure/Error: attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"

Capybara::ElementNotFound:
Unable to find visible file field "picture" that is not disabled


My code is
(features/posts_spec.rb)



scenario "Access posting screen and post" do
   sign_in user
visit new_post_path
expect(page).to have_current_path(new_post_path)
fill_in "share impression", with: "hogehoge"
attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"
click_on "post"
expect(page).to have_current_path(posts_path)
end


(posts/new.html.erb)



 <div class="mb-3">
<%= f.label :picture %>
<%= f.file_field :picture %>
</div>


Please teach me a hint.










share|improve this question

























  • Show the actual HTML the erb template produces instead of the erb template

    – Thomas Walpole
    Dec 30 '18 at 17:23


















0















I want to test Image uploader.



My error is



Failure/Error: attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"

Capybara::ElementNotFound:
Unable to find visible file field "picture" that is not disabled


My code is
(features/posts_spec.rb)



scenario "Access posting screen and post" do
   sign_in user
visit new_post_path
expect(page).to have_current_path(new_post_path)
fill_in "share impression", with: "hogehoge"
attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"
click_on "post"
expect(page).to have_current_path(posts_path)
end


(posts/new.html.erb)



 <div class="mb-3">
<%= f.label :picture %>
<%= f.file_field :picture %>
</div>


Please teach me a hint.










share|improve this question

























  • Show the actual HTML the erb template produces instead of the erb template

    – Thomas Walpole
    Dec 30 '18 at 17:23
















0












0








0








I want to test Image uploader.



My error is



Failure/Error: attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"

Capybara::ElementNotFound:
Unable to find visible file field "picture" that is not disabled


My code is
(features/posts_spec.rb)



scenario "Access posting screen and post" do
   sign_in user
visit new_post_path
expect(page).to have_current_path(new_post_path)
fill_in "share impression", with: "hogehoge"
attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"
click_on "post"
expect(page).to have_current_path(posts_path)
end


(posts/new.html.erb)



 <div class="mb-3">
<%= f.label :picture %>
<%= f.file_field :picture %>
</div>


Please teach me a hint.










share|improve this question
















I want to test Image uploader.



My error is



Failure/Error: attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"

Capybara::ElementNotFound:
Unable to find visible file field "picture" that is not disabled


My code is
(features/posts_spec.rb)



scenario "Access posting screen and post" do
   sign_in user
visit new_post_path
expect(page).to have_current_path(new_post_path)
fill_in "share impression", with: "hogehoge"
attach_file "picture", "#{Rails.root}/spec/files/attachment.jpg"
click_on "post"
expect(page).to have_current_path(posts_path)
end


(posts/new.html.erb)



 <div class="mb-3">
<%= f.label :picture %>
<%= f.file_field :picture %>
</div>


Please teach me a hint.







ruby-on-rails ruby capybara






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 7:34









anothermh

3,25831632




3,25831632










asked Dec 30 '18 at 14:24







user10358924




















  • Show the actual HTML the erb template produces instead of the erb template

    – Thomas Walpole
    Dec 30 '18 at 17:23





















  • Show the actual HTML the erb template produces instead of the erb template

    – Thomas Walpole
    Dec 30 '18 at 17:23



















Show the actual HTML the erb template produces instead of the erb template

– Thomas Walpole
Dec 30 '18 at 17:23







Show the actual HTML the erb template produces instead of the erb template

– Thomas Walpole
Dec 30 '18 at 17:23














1 Answer
1






active

oldest

votes


















0














attach_file locates the file input element by it's id, name, or associated label text, so picture obviously doesn't match any of those. Without the actual HTML produced by your erb template it's impossible to tell exactly what the attributes for your input are, but taking a guess based on your route names you probably want something like one of the following



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg" # match id of the file input
attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg" # match name of the file input
attach_file "Picture", "#{Rails.root}/spec/files/attachment.jpg" # match associated label text


The other potential issue you may be dealing with is CSS styling of your file input. If your file input is actually styled to be non-visible and then replaced with some sort of button or image, to make it look nicer, then you will want to use the make_visible option which can be passed to attach_file. That will temporarily adjust the CSS to make the input visible - attach the file - and then reset the CSS to original state. Something like



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg", make_visible: true





share|improve this answer
























  • I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

    – user10358924
    Dec 31 '18 at 1:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53978413%2fi-want-to-do-image-upload-testfeature-spec%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














attach_file locates the file input element by it's id, name, or associated label text, so picture obviously doesn't match any of those. Without the actual HTML produced by your erb template it's impossible to tell exactly what the attributes for your input are, but taking a guess based on your route names you probably want something like one of the following



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg" # match id of the file input
attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg" # match name of the file input
attach_file "Picture", "#{Rails.root}/spec/files/attachment.jpg" # match associated label text


The other potential issue you may be dealing with is CSS styling of your file input. If your file input is actually styled to be non-visible and then replaced with some sort of button or image, to make it look nicer, then you will want to use the make_visible option which can be passed to attach_file. That will temporarily adjust the CSS to make the input visible - attach the file - and then reset the CSS to original state. Something like



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg", make_visible: true





share|improve this answer
























  • I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

    – user10358924
    Dec 31 '18 at 1:24
















0














attach_file locates the file input element by it's id, name, or associated label text, so picture obviously doesn't match any of those. Without the actual HTML produced by your erb template it's impossible to tell exactly what the attributes for your input are, but taking a guess based on your route names you probably want something like one of the following



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg" # match id of the file input
attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg" # match name of the file input
attach_file "Picture", "#{Rails.root}/spec/files/attachment.jpg" # match associated label text


The other potential issue you may be dealing with is CSS styling of your file input. If your file input is actually styled to be non-visible and then replaced with some sort of button or image, to make it look nicer, then you will want to use the make_visible option which can be passed to attach_file. That will temporarily adjust the CSS to make the input visible - attach the file - and then reset the CSS to original state. Something like



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg", make_visible: true





share|improve this answer
























  • I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

    – user10358924
    Dec 31 '18 at 1:24














0












0








0







attach_file locates the file input element by it's id, name, or associated label text, so picture obviously doesn't match any of those. Without the actual HTML produced by your erb template it's impossible to tell exactly what the attributes for your input are, but taking a guess based on your route names you probably want something like one of the following



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg" # match id of the file input
attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg" # match name of the file input
attach_file "Picture", "#{Rails.root}/spec/files/attachment.jpg" # match associated label text


The other potential issue you may be dealing with is CSS styling of your file input. If your file input is actually styled to be non-visible and then replaced with some sort of button or image, to make it look nicer, then you will want to use the make_visible option which can be passed to attach_file. That will temporarily adjust the CSS to make the input visible - attach the file - and then reset the CSS to original state. Something like



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg", make_visible: true





share|improve this answer













attach_file locates the file input element by it's id, name, or associated label text, so picture obviously doesn't match any of those. Without the actual HTML produced by your erb template it's impossible to tell exactly what the attributes for your input are, but taking a guess based on your route names you probably want something like one of the following



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg" # match id of the file input
attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg" # match name of the file input
attach_file "Picture", "#{Rails.root}/spec/files/attachment.jpg" # match associated label text


The other potential issue you may be dealing with is CSS styling of your file input. If your file input is actually styled to be non-visible and then replaced with some sort of button or image, to make it look nicer, then you will want to use the make_visible option which can be passed to attach_file. That will temporarily adjust the CSS to make the input visible - attach the file - and then reset the CSS to original state. Something like



attach_file 'post_picture', "#{Rails.root}/spec/files/attachment.jpg", make_visible: true






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 30 '18 at 22:45









Thomas WalpoleThomas Walpole

30.7k32748




30.7k32748













  • I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

    – user10358924
    Dec 31 '18 at 1:24



















  • I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

    – user10358924
    Dec 31 '18 at 1:24

















I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

– user10358924
Dec 31 '18 at 1:24





I change attach_file "post[picture]", "#{Rails.root}/spec/files/attachment.jpg"and was able to solve the problem. Thank you so much!

– user10358924
Dec 31 '18 at 1:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53978413%2fi-want-to-do-image-upload-testfeature-spec%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'