Received following error for my Capybara test in terminal:
Failures:
1) Users User create new user
Failure/Error: fill_in 'Username', with: 'Ali', visible: false
Capybara::ElementNotFound:
Unable to find field "Username" that is not disabled within #<Capybara::Node::Element tag="form" path="/html/body/form">
# ./spec/features/users_spec.rb:31:in `block (4 levels) in <top (required)>'
# ./spec/features/users_spec.rb:30:in `block (3 levels) in <top (required)>
My test code in capybara:
require 'rails_helper'
RSpec.feature "Users", type: :feature do
describe "User", :type => :feature do
it "create new user" do
visit '/signup'
within('form') do
fill_in 'Username', with: 'Ali', visible: false
fill_in 'Password', with: 'ali', visible: false
end
click_button 'Submit'
expect(page).to have_content 'User successfully created.'
end
end
end
My view file
<h1>Create New User</h1>
<%= form_for :user, url: '/users' do |f| %>
Username: <%= f.text_field :username %>
Password: <%= f.password_field :password %>
Uplaod your photo: <%= f.file_field :image %>
<%= f.submit "Submit" %>
<% end %>
And my controller:
def create
user = User.new(user_params)
if user.save
redirect_to '/users/index', notice: 'User successfully created.'
else
redirect_to '/signup'
end
end
I did some research, this was due to the issue on capybara 2x, and most peoples solved by adding visible: false, but this solution couldn't works on me.
Appreciate for the help from the pro out there.