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

Commit

Permalink
Adding an 'ignoreSynchronization' property to turn off Protractor's a…
Browse files Browse the repository at this point in the history
…ttempt to

wait for Angular to be ready on a page. This can be used to test pages that
poll with $timeout or $http.
  • Loading branch information
juliemr committed Sep 6, 2013
1 parent e61873b commit 73821fb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
39 changes: 38 additions & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,42 @@ var Protractor = function(webdriver, opt_baseUrl, opt_rootElement) {
}
}

/**
* The wrapped webdriver instance. Use this to interact with pages that do
* not contain Angular (such as a log-in screen).
*
* @type {webdriver.WebDriver}
*/
this.driver = webdriver;

/**
* All get methods will be resolved against this base URL. Relative URLs are =
* resolved the way anchor tags resolve.
*
* @type {string}
*/
this.baseUrl = opt_baseUrl || '';

/**
* The css selector for anmelement on which to find Angular. This is usually
* 'body' but if your ng-app is on a subsection of the page it may be
* a subelement.
*
* @type {string}
*/
this.rootEl = opt_rootElement || 'body';

/**
* If true, Protractor will not attempt to synchronize with the page before
* performing actions. This can be harmful because Protractor will not wait
* until $timeouts and $http calls have been processed, which can cause
* tests to become flaky. This should be used only when necessary, such as
* when a page continuously polls an API using $timeout.
*
* @type {boolean}
*/
this.ignoreSynchronization = false;

this.moduleNames_ = [];

this.moduleScripts_ = [];
Expand All @@ -336,7 +369,11 @@ var Protractor = function(webdriver, opt_baseUrl, opt_rootElement) {
* scripts return value.
*/
Protractor.prototype.waitForAngular = function() {
return this.driver.executeAsyncScript(clientSideScripts.waitForAngular, this.rootEl);
if (this.ignoreSynchronization) {
return webdriver.promise.fulfilled();
}
return this.driver.executeAsyncScript(
clientSideScripts.waitForAngular, this.rootEl);
};

// TODO: activeelement also returns a WebElement.
Expand Down
18 changes: 16 additions & 2 deletions spec/polling_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('synchronizing with pages that poll', function() {
ptor.get('app/index.html#/polling');
});

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

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

startButton.click();

// Turn this on to see timeouts.
ptor.ignoreSynchronization = true;

count.getText().then(function(text) {
expect(text).toBeGreaterThan(2);
expect(text).toBeGreaterThan(-1);
});

ptor.sleep(2000);

count.getText().then(function(text) {
expect(text).toBeGreaterThan(1);
});
});

afterEach(function() {
// Remember to turn it off when you're done!
ptor.ignoreSynchronization = false;
});
});

0 comments on commit 73821fb

Please sign in to comment.