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

Commit c22fc38

Browse files
committed
fix(sync): getCurrentUrl and friends should sync with Angular first
getCurrentUrl, getPageSource, and getTitle should sync with Angular before executing. Closes #92.
1 parent d5621d9 commit c22fc38

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/clientsidescripts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ clientSideScripts.findSelectedOption = function() {
305305
* arguments[0] {Element} The scope of the search.
306306
* arguments[1] {string} The model name.
307307
*
308-
* @return {Array.<Element?} The matching select elements.
308+
* @return {Array.<Element>} The matching select elements.
309309
*/
310310
clientSideScripts.findSelectedOptions = function() {
311311
var using = arguments[0] || document;

lib/protractor.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ for (foo in webdriver) {
2020
* @param {Object} to
2121
* @param {Object} from
2222
* @param {string} fnName
23+
* @param {function=} setupFn
2324
*/
24-
var mixin = function(to, from, fnName) {
25+
var mixin = function(to, from, fnName, setupFn) {
2526
to[fnName] = function() {
27+
if (setupFn) {
28+
setupFn();
29+
}
2630
return from[fnName].apply(from, arguments);
2731
}
2832
};
2933

30-
3134
/**
3235
* @param {webdriver.WebDriver} webdriver
3336
* @param {string=} opt_baseUrl A base URL to run get requests against.
@@ -36,10 +39,19 @@ var mixin = function(to, from, fnName) {
3639
* @constructor
3740
*/
3841
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+
3947
// 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+
}
4355
}
4456
}
4557

@@ -227,6 +239,7 @@ Protractor.prototype.findElements = function(locator, varArgs) {
227239
* the element is present on the page.
228240
*/
229241
Protractor.prototype.isElementPresent = function(locatorOrElement, varArgs) {
242+
this.waitForAngular();
230243
if (locatorOrElement.findArrayOverride) {
231244
return locatorOrElement.findArrayOverride(this.driver).then(function(arr) {
232245
return !!arr.length;

0 commit comments

Comments
 (0)