好的,所以我正在使用 capybara + rails 3 + rspect
我正在尝试登录我的网站,但即使我在使用该fill_in
方法时没有收到错误,但我还是收到了该方法的错误 click_on
,因为它找不到我要单击的元素。
这是我的 HTML 代码:
<form accept-charset="UTF-8" action="/" class="filter_form" id="login" method="post">
<fieldset>
<div class="modal-body">
<div class="clearfix login-fields">
<label for="user_email">Email</label>
<div class="input login-inputs">
<input class="input-text" id="user_email" name="user[email]" placeholder="email" size="30" type="email" value="">
</div>
</div>
<div class="clearfix login-fields">
<label for="user_password">Password</label>
<div class="input login-inputs">
<input class="input-text" id="user_password" name="user[password]" placeholder="password" size="30" type="password">
</div>
</div>
</div>
<div class="modal-footer">
<input class="btn btn-primary login_btn" id="btn_login" name="commit" type="submit" value="Sign in">
<a href="/lms/forgot_password" class="btn">Forgot password...</a>
<a href="#" class="btn close cancel" data-dismiss="modal">Cancel</a>
</div>
</fieldset>
</form>
这是测试:
describe "Login ", js: true, type: :request do
it "should login correctly if the right credentials are given" do
Capybara.default_wait_time = 15
Capybara.ignore_hidden_elements = false
visit new_user_session_path
fill_in 'user_email', :with => 'example@test.com'
fill_in 'user_password', :with => 'pwd123'
p page.body
click_on 'Sign in'
visit '/'
save_and_open_page
response.should have_content('Welcome')
end
end
最糟糕的是,当我在看到以下代码p page.body
之前就这样做了:click_on
<html xmlns=\\\"http://www.w3.org/1999/xhtml\\\"><head></head><body></body></html>\
但是,如果我更改它,p response.body.inspect
那么我将获得页面的完整 html 代码......,该visit
方法不应该将响应的内容加载到page
?
任何帮助将不胜感激,这让我发疯:)