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

Commit eca7d65

Browse files
committed
Adding a test case which shows the problem with polling sites.
1 parent 78b6eca commit eca7d65

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

Diff for: spec/polling_spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var util = require('util');
2+
3+
describe('synchronizing with pages that poll', function() {
4+
var ptor = protractor.getInstance();
5+
6+
beforeEach(function() {
7+
ptor.get('app/index.html#/polling');
8+
});
9+
10+
it('times out :(', function() {
11+
var startButton =
12+
ptor.findElement(protractor.By.id('pollstarter'));
13+
14+
var count = ptor.findElement(protractor.By.binding('count'));
15+
expect(count.getText()).toEqual('0');
16+
17+
startButton.click();
18+
19+
count.getText().then(function(text) {
20+
expect(text).toBeGreaterThan(2);
21+
});
22+
});
23+
});

Diff for: testapp/app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<li><a href="#/form">form</a></li>
1414
<li><a href="#/async">async</a></li>
1515
<li><a href="#/conflict">conflict</a></li>
16+
<li><a href="#/polling">polling</a></li>
1617
</ul>
1718

1819
<div ng-view></div>

Diff for: testapp/app/js/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives'])
1010
$routeProvider.when('/form', {templateUrl: 'partials/form.html', controller: FormCtrl});
1111
$routeProvider.when('/async', {templateUrl: 'partials/async.html', controller: AsyncCtrl});
1212
$routeProvider.when('/conflict', {templateUrl: 'partials/conflict.html', controller: ConflictCtrl});
13+
$routeProvider.when('/polling', {templateUrl: 'partials/polling.html', controller: PollingCtrl});
1314
$routeProvider.otherwise({redirectTo: '/http'});
1415
}]);

Diff for: testapp/app/js/controllers.js

+16
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,19 @@ function ConflictCtrl($scope) {
178178
}]
179179
};
180180
ConflictCtrl.$inject = ['$scope'];
181+
182+
function PollingCtrl($scope, $timeout) {
183+
$scope.count = 0;
184+
185+
$scope.startPolling = function() {
186+
function poll() {
187+
$timeout(function() {
188+
$scope.count++;
189+
poll();
190+
}, 1000);
191+
};
192+
193+
poll();
194+
};
195+
};
196+
PollingCtrl.$inject = ['$scope', '$timeout'];

Diff for: testapp/app/partials/polling.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>This view shows a controller which uses a polling mechanism to
2+
contact the server. It is constantly using angular's $timeout.</div>
3+
<button id="pollstarter" ng-click="startPolling()">Start Polling</button>
4+
<div>{{count}}</div>

0 commit comments

Comments
 (0)