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

Commit 8329b01

Browse files
committed
Adding waitForAngular calls before WebElement functions. Closes #37.
1 parent 0e8de99 commit 8329b01

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

lib/protractor.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,23 @@ Protractor.prototype.waitForAngular = function() {
346346
*
347347
* @param {webdriver.WebElement} element
348348
*/
349-
var wrapWebElement = function(element) {
349+
Protractor.prototype.wrapWebElement = function(element) {
350+
var thisPtor = this;
351+
// Before any of these WebElement functions, Protractor will wait to make sure
352+
// Angular is synched up.
353+
var functionsToSync = [
354+
'click', 'sendKeys', 'getTagName', 'getCssValue', 'getAttribute', 'getText',
355+
'getSize', 'getLocation', 'isEnabled', 'isSelected', 'submit', 'clear',
356+
'isDisplayed', 'getOuterHtml', 'getInnerHtml'];
357+
var originalFns = {};
358+
functionsToSync.forEach(function(name) {
359+
originalFns[name] = element[name];
360+
element[name] = function() {
361+
thisPtor.waitForAngular();
362+
return originalFns[name].apply(element, arguments);
363+
}
364+
});
365+
350366
var originalFindElement = element.findElement;
351367
var originalFindElements = element.findElements;
352368

@@ -355,6 +371,7 @@ var wrapWebElement = function(element) {
355371
* @return {!webdriver.WebElement}
356372
*/
357373
element.findElement = function(locator, varArgs) {
374+
thisPtor.waitForAngular();
358375
if (locator.findOverride) {
359376
return locator.findOverride(element.getDriver(), element);
360377
}
@@ -367,6 +384,7 @@ var wrapWebElement = function(element) {
367384
* array of the located {@link webdriver.WebElement}s.
368385
*/
369386
element.findElements = function(locator, varArgs) {
387+
thisPtor.waitForAngular();
370388
if (locator.findArrayOverride) {
371389
return locator.findArrayOverride(element.getDriver(), element);
372390
}
@@ -384,8 +402,8 @@ var wrapWebElement = function(element) {
384402
* will be returned as a WebElement.
385403
*/
386404
element.evaluate = function(expression) {
387-
// put into clientSideScripts
388-
// Should this be a function of WebElement? (yes)
405+
// TODO: put into clientSideScripts
406+
thisPtor.waitForAngular();
389407
return element.getDriver().executeScript(function() {
390408
var element = arguments[0];
391409
var expression = arguments[1];
@@ -405,9 +423,9 @@ var wrapWebElement = function(element) {
405423
Protractor.prototype.findElement = function(locator, varArgs) {
406424
this.waitForAngular();
407425
if (locator.findOverride) {
408-
return wrapWebElement(locator.findOverride(this.driver));
426+
return this.wrapWebElement(locator.findOverride(this.driver));
409427
}
410-
return wrapWebElement(this.driver.findElement(locator, varArgs));
428+
return this.wrapWebElement(this.driver.findElement(locator, varArgs));
411429
};
412430

413431
/**
@@ -417,11 +435,12 @@ Protractor.prototype.findElement = function(locator, varArgs) {
417435
* array of the located {@link webdriver.WebElement}s.
418436
*/
419437
Protractor.prototype.findElements = function(locator, varArgs) {
438+
var self = this;
420439
this.waitForAngular();
421440
if (locator.findArrayOverride) {
422441
return locator.findArrayOverride(this.driver).then(function(elems) {
423442
for (var i = 0; i < elems.length; ++i) {
424-
wrapWebElement(elems[i]);
443+
self.wrapWebElement(elems[i]);
425444
}
426445
return elems;
427446
});

spec/synchronize_spec.js

-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe('synchronizing with slow pages', function() {
1515
expect(status.getText()).toEqual('not started');
1616

1717
button.click();
18-
ptor.waitForAngular();
1918

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

3130
button.click();
32-
ptor.waitForAngular();
3331

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

4543
button.click();
46-
ptor.waitForAngular();
4744

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

5956
button.click();
60-
ptor.waitForAngular();
6157

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

7571
button.click();
76-
ptor.waitForAngular();
7772

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

8984
button.click();
90-
ptor.waitForAngular();
9185

9286
expect(status.getText()).toEqual('done');
9387
});

0 commit comments

Comments
 (0)