I want to do Image upload test(feature spec)
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
add a comment |
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
Show the actual HTML the erb template produces instead of the erb template
– Thomas Walpole
Dec 30 '18 at 17:23
add a comment |
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
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
ruby-on-rails ruby capybara
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
I changeattach_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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
I changeattach_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
add a comment |
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
I changeattach_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
add a comment |
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
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
answered Dec 30 '18 at 22:45
Thomas WalpoleThomas Walpole
30.7k32748
30.7k32748
I changeattach_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
add a comment |
I changeattach_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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Show the actual HTML the erb template produces instead of the erb template
– Thomas Walpole
Dec 30 '18 at 17:23