我正在测试最小的水豚,我的一次测试出错了
Unable to find link or button "Edit Profile"
这是我的测试
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
测试助手的两个辅助方法
def dude_sign_up
visit new_user_path
fill_in "Name", with: 'thedude'
fill_in "Email", with: "dude@dudecool.com"
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: "dude@dudecool.com"
fill_in "Password", with: 'password'
click_on "Log In"
end
如果它需要我的这里是我的_nav,我在application.html.erb中生成了在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>
如果我只是点击所有内容并通过它就可以正常工作。我没有使用灯具是我的问题的原因吗?
答案 0 :(得分:1)
当Capybara寻找元素时,它只会考虑用户可见的元素。
鉴于页面中的命名,我猜测用户首次登录时“编辑个人资料”不可见。要查看链接,用户可能需要先点击“注册”链接。
Capybara需要执行相同的工作流程。尝试添加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