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

Commit 73821fb

Browse files
committed
Adding an 'ignoreSynchronization' property to turn off Protractor's attempt to
wait for Angular to be ready on a page. This can be used to test pages that poll with $timeout or $http.
1 parent e61873b commit 73821fb

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

lib/protractor.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,42 @@ var Protractor = function(webdriver, opt_baseUrl, opt_rootElement) {
320320
}
321321
}
322322

323+
/**
324+
* The wrapped webdriver instance. Use this to interact with pages that do
325+
* not contain Angular (such as a log-in screen).
326+
*
327+
* @type {webdriver.WebDriver}
328+
*/
323329
this.driver = webdriver;
330+
331+
/**
332+
* All get methods will be resolved against this base URL. Relative URLs are =
333+
* resolved the way anchor tags resolve.
334+
*
335+
* @type {string}
336+
*/
324337
this.baseUrl = opt_baseUrl || '';
338+
339+
/**
340+
* The css selector for anmelement on which to find Angular. This is usually
341+
* 'body' but if your ng-app is on a subsection of the page it may be
342+
* a subelement.
343+
*
344+
* @type {string}
345+
*/
325346
this.rootEl = opt_rootElement || 'body';
347+
348+
/**
349+
* If true, Protractor will not attempt to synchronize with the page before
350+
* performing actions. This can be harmful because Protractor will not wait
351+
* until $timeouts and $http calls have been processed, which can cause
352+
* tests to become flaky. This should be used only when necessary, such as
353+
* when a page continuously polls an API using $timeout.
354+
*
355+
* @type {boolean}
356+
*/
357+
this.ignoreSynchronization = false;
358+
326359
this.moduleNames_ = [];
327360

328361
this.moduleScripts_ = [];
@@ -336,7 +369,11 @@ var Protractor = function(webdriver, opt_baseUrl, opt_rootElement) {
336369
* scripts return value.
337370
*/
338371
Protractor.prototype.waitForAngular = function() {
339-
return this.driver.executeAsyncScript(clientSideScripts.waitForAngular, this.rootEl);
372+
if (this.ignoreSynchronization) {
373+
return webdriver.promise.fulfilled();
374+
}
375+
return this.driver.executeAsyncScript(
376+
clientSideScripts.waitForAngular, this.rootEl);
340377
};
341378

342379
// TODO: activeelement also returns a WebElement.

spec/polling_spec.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('synchronizing with pages that poll', function() {
77
ptor.get('app/index.html#/polling');
88
});
99

10-
it('times out :(', function() {
10+
it('avoids timeouts using ignoreSynchronization', function() {
1111
var startButton =
1212
ptor.findElement(protractor.By.id('pollstarter'));
1313

@@ -16,8 +16,22 @@ describe('synchronizing with pages that poll', function() {
1616

1717
startButton.click();
1818

19+
// Turn this on to see timeouts.
20+
ptor.ignoreSynchronization = true;
21+
1922
count.getText().then(function(text) {
20-
expect(text).toBeGreaterThan(2);
23+
expect(text).toBeGreaterThan(-1);
2124
});
25+
26+
ptor.sleep(2000);
27+
28+
count.getText().then(function(text) {
29+
expect(text).toBeGreaterThan(1);
30+
});
31+
});
32+
33+
afterEach(function() {
34+
// Remember to turn it off when you're done!
35+
ptor.ignoreSynchronization = false;
2236
});
2337
});

0 commit comments

Comments
 (0)