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

Commit

Permalink
Adding waitForAngular calls before WebElement functions. Closes #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemr committed Sep 4, 2013
1 parent 0e8de99 commit 8329b01
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 25 additions & 6 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,23 @@ Protractor.prototype.waitForAngular = function() {
*
* @param {webdriver.WebElement} element
*/
var wrapWebElement = function(element) {
Protractor.prototype.wrapWebElement = function(element) {
var thisPtor = this;
// Before any of these WebElement functions, Protractor will wait to make sure
// Angular is synched up.
var functionsToSync = [
'click', 'sendKeys', 'getTagName', 'getCssValue', 'getAttribute', 'getText',
'getSize', 'getLocation', 'isEnabled', 'isSelected', 'submit', 'clear',
'isDisplayed', 'getOuterHtml', 'getInnerHtml'];
var originalFns = {};
functionsToSync.forEach(function(name) {
originalFns[name] = element[name];
element[name] = function() {
thisPtor.waitForAngular();
return originalFns[name].apply(element, arguments);
}
});

var originalFindElement = element.findElement;
var originalFindElements = element.findElements;

Expand All @@ -355,6 +371,7 @@ var wrapWebElement = function(element) {
* @return {!webdriver.WebElement}
*/
element.findElement = function(locator, varArgs) {
thisPtor.waitForAngular();
if (locator.findOverride) {
return locator.findOverride(element.getDriver(), element);
}
Expand All @@ -367,6 +384,7 @@ var wrapWebElement = function(element) {
* array of the located {@link webdriver.WebElement}s.
*/
element.findElements = function(locator, varArgs) {
thisPtor.waitForAngular();
if (locator.findArrayOverride) {
return locator.findArrayOverride(element.getDriver(), element);
}
Expand All @@ -384,8 +402,8 @@ var wrapWebElement = function(element) {
* will be returned as a WebElement.
*/
element.evaluate = function(expression) {
// put into clientSideScripts
// Should this be a function of WebElement? (yes)
// TODO: put into clientSideScripts
thisPtor.waitForAngular();
return element.getDriver().executeScript(function() {
var element = arguments[0];
var expression = arguments[1];
Expand All @@ -405,9 +423,9 @@ var wrapWebElement = function(element) {
Protractor.prototype.findElement = function(locator, varArgs) {
this.waitForAngular();
if (locator.findOverride) {
return wrapWebElement(locator.findOverride(this.driver));
return this.wrapWebElement(locator.findOverride(this.driver));
}
return wrapWebElement(this.driver.findElement(locator, varArgs));
return this.wrapWebElement(this.driver.findElement(locator, varArgs));
};

/**
Expand All @@ -417,11 +435,12 @@ Protractor.prototype.findElement = function(locator, varArgs) {
* array of the located {@link webdriver.WebElement}s.
*/
Protractor.prototype.findElements = function(locator, varArgs) {
var self = this;
this.waitForAngular();
if (locator.findArrayOverride) {
return locator.findArrayOverride(this.driver).then(function(elems) {
for (var i = 0; i < elems.length; ++i) {
wrapWebElement(elems[i]);
self.wrapWebElement(elems[i]);
}
return elems;
});
Expand Down
6 changes: 0 additions & 6 deletions spec/synchronize_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('done');
});
Expand All @@ -29,7 +28,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('done');
});
Expand All @@ -43,7 +41,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('pending...');
});
Expand All @@ -57,7 +54,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('done');
});
Expand All @@ -73,7 +69,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('done');
});
Expand All @@ -87,7 +82,6 @@ describe('synchronizing with slow pages', function() {
expect(status.getText()).toEqual('not started');

button.click();
ptor.waitForAngular();

expect(status.getText()).toEqual('done');
});
Expand Down

0 comments on commit 8329b01

Please sign in to comment.