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')
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.
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.
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%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With