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

Commit

Permalink
feat(protractor): new API allowAnimations(bool) on protractor elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
chirayuk authored and juliemr committed May 27, 2014
1 parent 8ccd752 commit f23565d
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@ functions.evaluate = function(element, expression) {
return angular.element(element).scope().$eval(expression);
};

functions.allowAnimations = function(element, value) {
var ngElement = angular.element(element);
if (ngElement.allowAnimations) {
// AngularDart: $testability API.
return ngElement.allowAnimations(value);
} else {
// AngularJS
var enabledFn = ngElement.injector().get('$animate').enabled;
return (value == null) ? enabledFn() : enabledFn(value);
}
};

/**
* Return the current url using $location.absUrl().
*
Expand Down
8 changes: 7 additions & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var buildElementHelper = function(ptor, opt_usingChain) {
var elementFinder = {};

var webElementFns = WEB_ELEMENT_FUNCTIONS.concat(
['findElements', 'isElementPresent', 'evaluate']);
['findElements', 'isElementPresent', 'evaluate', 'allowAnimations']);
webElementFns.forEach(function(fnName) {
elementFinder[fnName] = function() {
var callerError = new Error();
Expand Down Expand Up @@ -780,6 +780,12 @@ Protractor.prototype.wrapWebElement = function(element) {
element, expression);
};

element.allowAnimations = function(value) {
thisPtor.waitForAngular();
return element.getDriver().executeScript(clientSideScripts.allowAnimations,
element, value);
};

return element;
};

Expand Down
22 changes: 19 additions & 3 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ describe('ElementFinder', function() {
{index: 2, text: 'form'},
{index: 3, text: 'async'},
{index: 4, text: 'conflict'},
{index: 5, text: 'polling'}
{index: 5, text: 'polling'},
{index: 6, text: 'animation'}
]);
});

Expand Down Expand Up @@ -186,7 +187,8 @@ describe('ElementFinder', function() {
newExpected('form'),
newExpected('async'),
newExpected('conflict'),
newExpected('polling')
newExpected('polling'),
newExpected('animation')
]);
});

Expand All @@ -197,7 +199,7 @@ describe('ElementFinder', function() {
return i++;
});

expect(labels).toEqual([1, 2, 3, 4, 5, 6]);
expect(labels).toEqual([1, 2, 3, 4, 5, 6, 7]);
});

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

it('should export an allowAnimations helper', function() {
browser.get('index.html#/animation');
var animationTop = element(by.id('animationTop'));
var toggledNode = element(by.id('toggledNode'));

expect(animationTop.allowAnimations()).toBe(true);
animationTop.allowAnimations(false);
expect(animationTop.allowAnimations()).toBe(false);

expect(toggledNode.isPresent()).toBe(true);
element(by.id('checkbox')).click();
expect(toggledNode.isPresent()).toBe(false);
});

it('should keep a reference to the original locator', function() {
browser.get('index.html#/form');

Expand Down
2 changes: 2 additions & 0 deletions testapp/alt_root_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</div>

<script src="lib/angular_v1.2.9/angular.min.js"></script>
<script src="lib/angular_v1.2.9/angular-animate.min.js"></script>
<script src="lib/angular_v1.2.9/angular-route.min.js"></script>
<script src="components/app-version.js"></script>
<script src="async/async.js"></script>
Expand All @@ -36,6 +37,7 @@
<script src="form/form.js"></script>
<script src="polling/polling.js"></script>
<script src="repeater/repeater.js"></script>
<script src="animation/animation.js"></script>
<script src="app.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions testapp/animation/animation.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#animationTop .animate-if {
background:white;
border:1px solid black;
padding:10px;
}

#animationTop .animate-if.ng-enter,
#animationTop .animate-if.ng-leave {
-webkit-transition:all linear 1s;
-moz-transition:all linear 1s;
-o-transition:all linear 1s;
transition:all linear 1s;

}

#animationTop .animate-if.ng-enter,
#animationTop .animate-if.ng-leave.ng-leave-active {
opacity:0;
}

#animationTop .animate-if.ng-leave,
#animationTop .animate-if.ng-enter.ng-enter-active {
opacity:1;
}
10 changes: 10 additions & 0 deletions testapp/animation/animation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- https://docs.angularjs.org/guide/animations -->
<div id="animationTop">
<label>
<input id="checkbox" type="checkbox" ng-model="checked" style="float:left; margin-right:10px;">
Click Me to toggle with animation
</label>
<div id="toggledNode" class="animate-if" ng-if="checked" style="clear:both;">
I exist!
</div>
</div>
5 changes: 5 additions & 0 deletions testapp/animation/animation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function AnimationCtrl($scope) {
$scope.checked = true;
};

AnimationCtrl.$inject = ['$scope'];
3 changes: 2 additions & 1 deletion testapp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@


// Declare app level module which depends on filters, and services
angular.module('myApp', ['ngRoute', 'myApp.appVersion']).
angular.module('myApp', ['ngAnimate', 'ngRoute', 'myApp.appVersion']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/repeater', {templateUrl: 'repeater/repeater.html', controller: RepeaterCtrl});
$routeProvider.when('/bindings', {templateUrl: 'bindings/bindings.html', controller: BindingsCtrl});
$routeProvider.when('/form', {templateUrl: 'form/form.html', controller: FormCtrl});
$routeProvider.when('/async', {templateUrl: 'async/async.html', controller: AsyncCtrl});
$routeProvider.when('/conflict', {templateUrl: 'conflict/conflict.html', controller: ConflictCtrl});
$routeProvider.when('/polling', {templateUrl: 'polling/polling.html', controller: PollingCtrl});
$routeProvider.when('/animation', {templateUrl: 'animation/animation.html', controller: AnimationCtrl});
$routeProvider.when('/slowloader', {
templateUrl: 'polling/polling.html',
controller: PollingCtrl,
Expand Down
5 changes: 5 additions & 0 deletions testapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="animation/animation.css"/>
</head>
<body>
<ul class="menu">
Expand All @@ -13,21 +14,25 @@
<li><a href="#/async">async</a></li>
<li><a href="#/conflict">conflict</a></li>
<li><a href="#/polling">polling</a></li>
<li><a href="#/animation">animation</a></li>
</ul>

<div ng-view></div>

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

<script src="lib/angular_v1.2.9/angular.min.js"></script>
<script src="lib/angular_v1.2.9/angular-animate.min.js"></script>
<script src="lib/angular_v1.2.9/angular-route.min.js"></script>

<script src="components/app-version.js"></script>
<script src="async/async.js"></script>
<script src="bindings/bindings.js"></script>
<script src="conflict/conflict.js"></script>
<script src="form/form.js"></script>
<script src="polling/polling.js"></script>
<script src="repeater/repeater.js"></script>
<script src="animation/animation.js"></script>
<script src="app.js"></script>

</body>
Expand Down
25 changes: 25 additions & 0 deletions testapp/lib/angular_v1.2.9/angular-animate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions testapp/lib/angular_v1.2.9/angular-animate.min.js.map

Large diffs are not rendered by default.

0 comments on commit f23565d

Please sign in to comment.