rspec 功能测试未找到模态输入
rspec feature test not finding modal input
我有一个 rspec 测试试图在弹出模式表单中填写字段。相关行是
fill_in 'Name', with: 'Jo Blo'
错误信息是
Capybara::ElementNotFound:
Unable to find visible field "Name" that is not disabled
这意味着它正在查找该字段但将其视为已禁用。但是,如果我在失败时使用capybara-screenshot查看页面,该字段是可见的并且该字段的html是
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br>
<input type="text" name="user[name]" id="user_name">
</div>
即它没有被禁用。
该字段位于 div#modal_new_user
中。如果我将测试更改为
expect(page).to have_css '#modal_new_user'
fill_in 'Name', with: 'Jo Blo'
错误信息变为
Failure/Error: expect(page).to have_css '#modal_new_user'
expected to find visible css "#modal_new_user" but there were no
matches. Also found "", which matched the selector but not all filters.
这似乎暗示未找到模态,但是如果我看一下水豚的屏幕截图,模态的 html 是可见的。
我该如何解决这个问题?
我正在使用水豚 3.0.2 和 rspec-rails 3.7.2.
bootstrap模态的代码是
<div id='modal_new_user' class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Warning</h4>
<p>enter code here Right now there is a 10 day free trial. Just fill in the form below.</p>
</div>
<div class="modal-body">
<form class="edit_user" id="edit_user_12004" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="306T/5kB9pqb9sW6mdW+tXyCzfydEF2tf8wQMJXEICO5uQ/YEDVVYqg12l7Qe+lU4uELZy/d1VIhzZObk/FVcQ==" />
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br />
<input type="text" name="user[name]" id="user_name" />
</div>
<div class="field">
<label for="user_email">Email</label><sup>*</sup><br />
<input type="email" name="user[email]" id="user_email" />
</div>
<div class="field">
<label for="user_password">Password</label><sup>*</sup><br />
<input type="password" name="user[password]" id="user_password" />
</div>
<p id="terms">By creating your account, you are agreeing to the site <a target="_blank" href="/legal">Terms and Conditions</a>. You will not be spammed, we dislike spam as much as you do.
</p>
<input type="hidden" value="clubs#edit" name="user[referral]" id="user_referral" />
<div class="actions">
<input type="submit" name="commit" value="Join Now" class="btn btn-cta btn-cta-primary" data-disable-with="Join Now" />
</div>
</form> </div>
<div class="modal-footer right_close_button">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
原来测试有type: :system
,所以当我去掉这个时,测试通过了。如果 puma.rb 指定并发,似乎有一个 issue 和 rails 系统测试。
我有一个 rspec 测试试图在弹出模式表单中填写字段。相关行是
fill_in 'Name', with: 'Jo Blo'
错误信息是
Capybara::ElementNotFound:
Unable to find visible field "Name" that is not disabled
这意味着它正在查找该字段但将其视为已禁用。但是,如果我在失败时使用capybara-screenshot查看页面,该字段是可见的并且该字段的html是
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br>
<input type="text" name="user[name]" id="user_name">
</div>
即它没有被禁用。
该字段位于 div#modal_new_user
中。如果我将测试更改为
expect(page).to have_css '#modal_new_user'
fill_in 'Name', with: 'Jo Blo'
错误信息变为
Failure/Error: expect(page).to have_css '#modal_new_user'
expected to find visible css "#modal_new_user" but there were no
matches. Also found "", which matched the selector but not all filters.
这似乎暗示未找到模态,但是如果我看一下水豚的屏幕截图,模态的 html 是可见的。 我该如何解决这个问题?
我正在使用水豚 3.0.2 和 rspec-rails 3.7.2.
bootstrap模态的代码是
<div id='modal_new_user' class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Warning</h4>
<p>enter code here Right now there is a 10 day free trial. Just fill in the form below.</p>
</div>
<div class="modal-body">
<form class="edit_user" id="edit_user_12004" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="306T/5kB9pqb9sW6mdW+tXyCzfydEF2tf8wQMJXEICO5uQ/YEDVVYqg12l7Qe+lU4uELZy/d1VIhzZObk/FVcQ==" />
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br />
<input type="text" name="user[name]" id="user_name" />
</div>
<div class="field">
<label for="user_email">Email</label><sup>*</sup><br />
<input type="email" name="user[email]" id="user_email" />
</div>
<div class="field">
<label for="user_password">Password</label><sup>*</sup><br />
<input type="password" name="user[password]" id="user_password" />
</div>
<p id="terms">By creating your account, you are agreeing to the site <a target="_blank" href="/legal">Terms and Conditions</a>. You will not be spammed, we dislike spam as much as you do.
</p>
<input type="hidden" value="clubs#edit" name="user[referral]" id="user_referral" />
<div class="actions">
<input type="submit" name="commit" value="Join Now" class="btn btn-cta btn-cta-primary" data-disable-with="Join Now" />
</div>
</form> </div>
<div class="modal-footer right_close_button">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
原来测试有type: :system
,所以当我去掉这个时,测试通过了。如果 puma.rb 指定并发,似乎有一个 issue 和 rails 系统测试。