Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit f23565d

Browse files
chirayukjuliemr
authored andcommitted
feat(protractor): new API allowAnimations(bool) on protractor elements.
1 parent 8ccd752 commit f23565d

11 files changed

+119
-5
lines changed

lib/clientsidescripts.js

+12
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,18 @@ functions.evaluate = function(element, expression) {
475475
return angular.element(element).scope().$eval(expression);
476476
};
477477

478+
functions.allowAnimations = function(element, value) {
479+
var ngElement = angular.element(element);
480+
if (ngElement.allowAnimations) {
481+
// AngularDart: $testability API.
482+
return ngElement.allowAnimations(value);
483+
} else {
484+
// AngularJS
485+
var enabledFn = ngElement.injector().get('$animate').enabled;
486+
return (value == null) ? enabledFn() : enabledFn(value);
487+
}
488+
};
489+
478490
/**
479491
* Return the current url using $location.absUrl().
480492
*

lib/protractor.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ var buildElementHelper = function(ptor, opt_usingChain) {
106106
var elementFinder = {};
107107

108108
var webElementFns = WEB_ELEMENT_FUNCTIONS.concat(
109-
['findElements', 'isElementPresent', 'evaluate']);
109+
['findElements', 'isElementPresent', 'evaluate', 'allowAnimations']);
110110
webElementFns.forEach(function(fnName) {
111111
elementFinder[fnName] = function() {
112112
var callerError = new Error();
@@ -780,6 +780,12 @@ Protractor.prototype.wrapWebElement = function(element) {
780780
element, expression);
781781
};
782782

783+
element.allowAnimations = function(value) {
784+
thisPtor.waitForAngular();
785+
return element.getDriver().executeScript(clientSideScripts.allowAnimations,
786+
element, value);
787+
};
788+
783789
return element;
784790
};
785791

spec/basic/elements_spec.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ describe('ElementFinder', function() {
158158
{index: 2, text: 'form'},
159159
{index: 3, text: 'async'},
160160
{index: 4, text: 'conflict'},
161-
{index: 5, text: 'polling'}
161+
{index: 5, text: 'polling'},
162+
{index: 6, text: 'animation'}
162163
]);
163164
});
164165

@@ -186,7 +187,8 @@ describe('ElementFinder', function() {
186187
newExpected('form'),
187188
newExpected('async'),
188189
newExpected('conflict'),
189-
newExpected('polling')
190+
newExpected('polling'),
191+
newExpected('animation')
190192
]);
191193
});
192194

@@ -197,7 +199,7 @@ describe('ElementFinder', function() {
197199
return i++;
198200
});
199201

200-
expect(labels).toEqual([1, 2, 3, 4, 5, 6]);
202+
expect(labels).toEqual([1, 2, 3, 4, 5, 6, 7]);
201203
});
202204

203205
it('should export an isPresent helper', function() {
@@ -207,6 +209,20 @@ describe('ElementFinder', function() {
207209
expect(element(by.binding('nopenopenope')).isPresent()).toBe(false);
208210
});
209211

212+
it('should export an allowAnimations helper', function() {
213+
browser.get('index.html#/animation');
214+
var animationTop = element(by.id('animationTop'));
215+
var toggledNode = element(by.id('toggledNode'));
216+
217+
expect(animationTop.allowAnimations()).toBe(true);
218+
animationTop.allowAnimations(false);
219+
expect(animationTop.allowAnimations()).toBe(false);
220+
221+
expect(toggledNode.isPresent()).toBe(true);
222+
element(by.id('checkbox')).click();
223+
expect(toggledNode.isPresent()).toBe(false);
224+
});
225+
210226
it('should keep a reference to the original locator', function() {
211227
browser.get('index.html#/form');
212228

testapp/alt_root_index.html

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</div>
2929

3030
<script src="lib/angular_v1.2.9/angular.min.js"></script>
31+
<script src="lib/angular_v1.2.9/angular-animate.min.js"></script>
3132
<script src="lib/angular_v1.2.9/angular-route.min.js"></script>
3233
<script src="components/app-version.js"></script>
3334
<script src="async/async.js"></script>
@@ -36,6 +37,7 @@
3637
<script src="form/form.js"></script>
3738
<script src="polling/polling.js"></script>
3839
<script src="repeater/repeater.js"></script>
40+
<script src="animation/animation.js"></script>
3941
<script src="app.js"></script>
4042
</body>
4143
</html>

testapp/animation/animation.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#animationTop .animate-if {
2+
background:white;
3+
border:1px solid black;
4+
padding:10px;
5+
}
6+
7+
#animationTop .animate-if.ng-enter,
8+
#animationTop .animate-if.ng-leave {
9+
-webkit-transition:all linear 1s;
10+
-moz-transition:all linear 1s;
11+
-o-transition:all linear 1s;
12+
transition:all linear 1s;
13+
14+
}
15+
16+
#animationTop .animate-if.ng-enter,
17+
#animationTop .animate-if.ng-leave.ng-leave-active {
18+
opacity:0;
19+
}
20+
21+
#animationTop .animate-if.ng-leave,
22+
#animationTop .animate-if.ng-enter.ng-enter-active {
23+
opacity:1;
24+
}

testapp/animation/animation.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- https://docs.angularjs.org/guide/animations -->
2+
<div id="animationTop">
3+
<label>
4+
<input id="checkbox" type="checkbox" ng-model="checked" style="float:left; margin-right:10px;">
5+
Click Me to toggle with animation
6+
</label>
7+
<div id="toggledNode" class="animate-if" ng-if="checked" style="clear:both;">
8+
I exist!
9+
</div>
10+
</div>

testapp/animation/animation.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function AnimationCtrl($scope) {
2+
$scope.checked = true;
3+
};
4+
5+
AnimationCtrl.$inject = ['$scope'];

testapp/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33

44
// Declare app level module which depends on filters, and services
5-
angular.module('myApp', ['ngRoute', 'myApp.appVersion']).
5+
angular.module('myApp', ['ngAnimate', 'ngRoute', 'myApp.appVersion']).
66
config(['$routeProvider', function($routeProvider) {
77
$routeProvider.when('/repeater', {templateUrl: 'repeater/repeater.html', controller: RepeaterCtrl});
88
$routeProvider.when('/bindings', {templateUrl: 'bindings/bindings.html', controller: BindingsCtrl});
99
$routeProvider.when('/form', {templateUrl: 'form/form.html', controller: FormCtrl});
1010
$routeProvider.when('/async', {templateUrl: 'async/async.html', controller: AsyncCtrl});
1111
$routeProvider.when('/conflict', {templateUrl: 'conflict/conflict.html', controller: ConflictCtrl});
1212
$routeProvider.when('/polling', {templateUrl: 'polling/polling.html', controller: PollingCtrl});
13+
$routeProvider.when('/animation', {templateUrl: 'animation/animation.html', controller: AnimationCtrl});
1314
$routeProvider.when('/slowloader', {
1415
templateUrl: 'polling/polling.html',
1516
controller: PollingCtrl,

testapp/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<title>My AngularJS App</title>
66
<link rel="stylesheet" href="app.css"/>
7+
<link rel="stylesheet" href="animation/animation.css"/>
78
</head>
89
<body>
910
<ul class="menu">
@@ -13,21 +14,25 @@
1314
<li><a href="#/async">async</a></li>
1415
<li><a href="#/conflict">conflict</a></li>
1516
<li><a href="#/polling">polling</a></li>
17+
<li><a href="#/animation">animation</a></li>
1618
</ul>
1719

1820
<div ng-view></div>
1921

2022
<div>Angular seed app: v<span app-version></span></div>
2123

2224
<script src="lib/angular_v1.2.9/angular.min.js"></script>
25+
<script src="lib/angular_v1.2.9/angular-animate.min.js"></script>
2326
<script src="lib/angular_v1.2.9/angular-route.min.js"></script>
27+
2428
<script src="components/app-version.js"></script>
2529
<script src="async/async.js"></script>
2630
<script src="bindings/bindings.js"></script>
2731
<script src="conflict/conflict.js"></script>
2832
<script src="form/form.js"></script>
2933
<script src="polling/polling.js"></script>
3034
<script src="repeater/repeater.js"></script>
35+
<script src="animation/animation.js"></script>
3136
<script src="app.js"></script>
3237

3338
</body>

testapp/lib/angular_v1.2.9/angular-animate.min.js

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testapp/lib/angular_v1.2.9/angular-animate.min.js.map

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)