@@ -20,14 +20,17 @@ for (foo in webdriver) {
20
20
* @param {Object } to
21
21
* @param {Object } from
22
22
* @param {string } fnName
23
+ * @param {function= } setupFn
23
24
*/
24
- var mixin = function ( to , from , fnName ) {
25
+ var mixin = function ( to , from , fnName , setupFn ) {
25
26
to [ fnName ] = function ( ) {
27
+ if ( setupFn ) {
28
+ setupFn ( ) ;
29
+ }
26
30
return from [ fnName ] . apply ( from , arguments ) ;
27
31
}
28
32
} ;
29
33
30
-
31
34
/**
32
35
* @param {webdriver.WebDriver } webdriver
33
36
* @param {string= } opt_baseUrl A base URL to run get requests against.
@@ -36,10 +39,19 @@ var mixin = function(to, from, fnName) {
36
39
* @constructor
37
40
*/
38
41
var Protractor = function ( webdriver , opt_baseUrl , opt_rootElement ) {
42
+ // These functions should delegate to the webdriver instance, but should
43
+ // wait for Angular to sync up before performing the action. This does not
44
+ // include functions which are overridden by protractor below.
45
+ var methodsToSync = [ 'getCurrentUrl' , 'getPageSource' , 'getTitle' ] ;
46
+
39
47
// Mix all other driver functionality into Protractor.
40
- for ( var foo in webdriver ) {
41
- if ( ! this [ foo ] && typeof webdriver [ foo ] == 'function' ) {
42
- mixin ( this , webdriver , foo ) ;
48
+ for ( var method in webdriver ) {
49
+ if ( ! this [ method ] && typeof webdriver [ method ] == 'function' ) {
50
+ if ( methodsToSync . indexOf ( method ) !== - 1 ) {
51
+ mixin ( this , webdriver , method , this . waitForAngular . bind ( this ) ) ;
52
+ } else {
53
+ mixin ( this , webdriver , method ) ;
54
+ }
43
55
}
44
56
}
45
57
@@ -227,6 +239,7 @@ Protractor.prototype.findElements = function(locator, varArgs) {
227
239
* the element is present on the page.
228
240
*/
229
241
Protractor . prototype . isElementPresent = function ( locatorOrElement , varArgs ) {
242
+ this . waitForAngular ( ) ;
230
243
if ( locatorOrElement . findArrayOverride ) {
231
244
return locatorOrElement . findArrayOverride ( this . driver ) . then ( function ( arr ) {
232
245
return ! ! arr . length ;
0 commit comments