问题描述
在Rails应用程序中,我尝试使用.有问题的部分如下:
In a Rails application I'm trying to test a Bootstrap modal with a jQuery TokenInput field in Rspec using Capybara with the capybara-webkit
driver. The portion in question is as follows:
click_link 'Create Team Modal'
sleep 1
within('div#modal_popup') do
fill_in 'input#token-input-team_name', with: 'Fancy team name'
sleep 1
fill_in 'input#token-input-team_name', with: '\t'
sleep 1
click_button 'Create Team'
end
page.should have_content('Fancy team name')
- 点击按钮获取模式信息
- 使用团队名称填充TokenInput
- 模拟Tab键使其处于选中状态
- 创建团队
- 验证名称是否显示在页面上
- Click button to get modal
- Fill in TokenInput with a team name
- Simulate a Tab key-press to get it selected
- Create the team
- Verify the name shows up on the page
这仅适用于所有已安装的sleep 1
;否则Capybara会在have_content
崩溃,最终会导致服务器错误,因为永远无法正确选择团队名称.但是,其他没有TokenInput的Bootstrap模态 在加载之前不需要sleep 1
.
This will only work with all those sleep 1
s in place; otherwise Capybara crashes at have_content
, eventually resulting in a server error because the team name was never able to be selected properly. Other Bootstrap modals without a TokenInput field do not require a sleep 1
before they load, however.
说了这么多,有什么办法可以摆脱睡眠,并使睡眠照常进行吗? Capybara 2删除了wait_until
(有充分的理由),因为它将在默认的等待时间内进行测试以测试某些内容……但这似乎并未反映在我的上述测试中;好像水豚在进入/退出此模式时没有参与该等待期.有人对此有经验吗?使用Rails 3.2.10,Rspec 2.12,Capybara 2,capybara-webkit 0.14.0,TokenInput 1.6.
With all that said, is there any way to get rid of the sleeps and have this proceed as normal? Capybara 2 took out wait_until
(with good reason) since it will wait within the default wait time to test for something...but that doesn't seem to be reflected in my above test; it's as if Capybara does not engage in that wait period upon entering/exiting this modal. Anyone have any experience with this? Using Rails 3.2.10, Rspec 2.12, Capybara 2, capybara-webkit 0.14.0, TokenInput 1.6.
推荐答案
尝试在测试环境中禁用动画,layouts/application.html.erb
Try disabling animations in test env, layouts/application.html.erb
<% if Rails.env.test? %>
<style type="text/css">
.modal.fade, .fade {
-webkit-transition: opacity 0.01s;
-moz-transition: opacity 0.01s;
-ms-transition: opacity 0.01s;
-o-transition: opacity 0.01s;
transition: opacity 0.01s;
}
</style>
<%end%>
这篇关于通过Capybara(v2)与Bootstrap模态进行交互时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!