【发布时间】:2014-05-25 12:17:37
【问题描述】:
在rspec-测试期间,我试图通过填写表格并单击“重置密码”链接来重置我的密码。
Capybara 给我以下错误:
1) ResetPasswords emails user a reset link when resetting password
Failure/Error: click_link 'Reset Password'
Capybara::ElementNotFound:
Unable to find link "Reset Password"
显然它没有找到我希望它点击的链接。但是当我尝试使用puts page.body 打印它正在查看的页面时,这个元素存在:
<div><input name="commit" type="submit" value="Reset Password" /></div>
我尝试使用click、click_button 和click_link,但没有使用雪茄。
为什么找不到元素?
更新 1:click_button 输出
1) ResetPasswords emails user a reset link when resetting password
Failure/Error: click_button 'Reset Password'
ActionView::Template::Error:
Missing host to link to! Please provide the :host parameter, set
default_url_options[:host], or set :only_path to true
更新 2:测试文件
require 'spec_helper'
include Warden::Test::Helpers
Warden.test_mode!
describe "ResetPasswords" do
it "emails user a reset link when resetting password" do
visit login_path
click_link 'password'
fill_in 'Email', :with => @user.email
puts page.body
click_link 'Reset Password'
page.should have_content "You will receive an email"
end
before(:each) do
@user = create(:user)
#login_as @user, :scope => :user
end
end
【问题讨论】:
-
click_button 'Reset Password'方法给出的输出是什么? -
请查看更新后的帖子。
-
如您所见,它找到了电子邮件字段并正确填写,我已经确认了这一点。但是,它不知道如何提交表单..
标签: ruby-on-rails rspec capybara