Can anyone suggest me how to disable animations in angular js application while executing protractor tests. I have added below code in my protractor config file but that does not help me:
var disableNgAnimate = function() { angular.module('disableNgAnimate', []).run(function($animate) { $animate.enabled(false); }); }; browser.addMockModule('disableNgAnimate', disableNgAnimate);
An animation is when the transformation of an HTML element gives you an illusion of motion.
You can control the timing of each transformation. Angular's animation system is built on CSS functionality, which means you can animate any property that the browser considers animatable.
In order to enable animations, we need to update index. html , loading the necessary dependencies (angular-animate. js and jquery. js) and the files that contain the CSS and JavaScript code used in CSS/JavaScript animations.
You can check out the angular's protractor configuration: https://github.com/angular/angular.js/blob/master/protractor-shared-conf.js
You should add it under onPrepare block:
onPrepare: function() { /* global angular: false, browser: false, jasmine: false */ // Disable animations so e2e tests run more quickly var disableNgAnimate = function() { angular.module('disableNgAnimate', []).run(['$animate', function($animate) { $animate.enabled(false); }]); }; browser.addMockModule('disableNgAnimate', disableNgAnimate);
I personally use the following code in the "onPrepare" function in my 'conf.js' file to disable both Angular/CSS animations:
... onPrepare: function() { var disableNgAnimate = function() { angular .module('disableNgAnimate', []) .run(['$animate', function($animate) { $animate.enabled(false); }]); }; var disableCssAnimate = function() { angular .module('disableCssAnimate', []) .run(function() { var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = '* {' + '-webkit-transition: none !important;' + '-moz-transition: none !important' + '-o-transition: none !important' + '-ms-transition: none !important' + 'transition: none !important' + '}'; document.getElementsByTagName('head')[0].appendChild(style); }); }; browser.addMockModule('disableNgAnimate', disableNgAnimate); browser.addMockModule('disableCssAnimate', disableCssAnimate); } ...
Please note: I did not write the above code, I found it online while looking for ways to speed up my own tests.
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