Reputation:
I'm currently testing with minitest capybara and I got an error on one of my tests
Unable to find link or button "Edit Profile"
here is my test
require "test_helper"
feature "as a student I want a working user system so grade = good" do
scenario "users can update profile" do
dude_sign_up
dude_log_in
click_on "Edit Profile"
click_on "Update"
page.must_have_content "Profile was successfully updated"
end
end
the two helper methods for test helper
def dude_sign_up
visit new_user_path
fill_in "Name", with: 'thedude'
fill_in "Email", with: "[email protected]"
fill_in "Password", with: 'password'
fill_in "Password confirmation", with: 'password'
click_on "Sign Up"
end
def dude_log_in
visit posts_path
fill_in "Email", with: "[email protected]"
fill_in "Password", with: 'password'
click_on "Log In"
end
and if its needed my here is my _nav that I have rendered in application.html.erb between and above the yield
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li><%= link_to 'Home', root_path %></li>
<li><%= link_to 'About', about_path %></li>
<li><%= link_to "The Blog", posts_path %></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Registration<b class="caret"></b></a>
<ul class="dropdown-menu">
<% if current_user %>
<td><%= link_to 'Edit Profile', edit_user_path(current_user) %></td>
<li><%= link_to "Users", users_path %></li>
<li><%= link_to "Log out", logout_path %></li>
<% else %>
<li><%= link_to 'Sign Up', signup_path %></a></li>
<li><%= link_to 'Log In', login_path %></li>
<% end %>
</ul>
</li>
</ul>
</div>
</nav>
it works fine if I just click on everything and go through it. I was not using fixtures is that the cause of my problem?
Upvotes: 0
Views: 409
Reputation: 46836
When Capybara looks for an element, it will only consider elements that are visible to the user.
Given the naming in your page, I am guessing that "Edit Profile" is not visible when the user first logs in. To see the link, the user likely needs to click the "Registration" link first.
Capybara needs to perform the same workflow. Try adding a click_on "Registration"
:
scenario "users can update profile" do
dude_sign_up
dude_log_in
click_on "Registration"
click_on "Edit Profile"
click_on "Update"
page.must_have_content "Profile was successfully updated"
end
Upvotes: 1