Disabling animation in Capybara tests

I have a lot of animations on my page, which really slows down my tests in capybara, because capybara often has to wait until the element is animated as it starts to hide.

I found this solution for all jQuery based animations:

<%= javascript_tag '$.fx.off = true;' if Rails.env.test? %>

However, I use twitter bootstrap, and most animations from bootstrap are produced by CSS 3 (with javascript backup). So my question is, is there a way to turn CSS3 transitions and animations into tests?

+6
source share
2 answers

You can try to create a reset transition and apply it to a specific element.

 .reset-transition { -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none; transition: none; } 

You can also apply it to everyone and put this css after Bootstrap

 * { -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none; transition: none; } 

You can make it more specific

 div, a, span, footer, header { -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none; transition: none; } 
+8
source
 # env.rb or spec_helper.rb Capybara.register_driver :poltergeist do |app| opts = { extensions: ["#{Rails.root}/features/support/phantomjs/disable_animations.js"] # or wherever } Capybara::Poltergeist::Driver.new(app, opts) end Capybara.javascript_driver = :poltergeist 

`` ``

 // disable_animations.js var disableAnimationStyles = '-webkit-transition: none !important;' + '-moz-transition: none !important;' + '-ms-transition: none !important;' + '-o-transition: none !important;' + 'transition: none !important;' window.onload = function() { var animationStyles = document.createElement('style'); animationStyles.type = 'text/css'; animationStyles.innerHTML = '* {' + disableAnimationStyles + '}'; document.head.appendChild(animationStyles); }; 

or only time

 var disableAnimationStyles = '-webkit-transition-duration: .0s !important;' + '-o-transition-duration: .0s !important;' + 'transition-duration: .0s !important;'; 
+3
source

Source: https://habr.com/ru/post/956954/


All Articles