Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable animations in protractor for angular js application

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); 
like image 632
user3345216 Avatar asked Oct 27 '14 09:10

user3345216


People also ask

What is animation in Angularjs?

An animation is when the transformation of an HTML element gives you an illusion of motion.

What is the benefit of angular animation?

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.

Which js file is required to play animation in an angular js application?

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.


2 Answers

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); 
like image 109
bugdayci Avatar answered Sep 24 '22 15:09

bugdayci


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.

like image 32
John Stennett Avatar answered Sep 25 '22 15:09

John Stennett