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

Commit

Permalink
fix(sync): getCurrentUrl and friends should sync with Angular first
Browse files Browse the repository at this point in the history
getCurrentUrl, getPageSource, and getTitle should sync with Angular
before executing. Closes #92.
  • Loading branch information
juliemr committed Sep 23, 2013
1 parent d5621d9 commit c22fc38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ clientSideScripts.findSelectedOption = function() {
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The model name.
*
* @return {Array.<Element?} The matching select elements.
* @return {Array.<Element>} The matching select elements.
*/
clientSideScripts.findSelectedOptions = function() {
var using = arguments[0] || document;
Expand Down
23 changes: 18 additions & 5 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ for (foo in webdriver) {
* @param {Object} to
* @param {Object} from
* @param {string} fnName
* @param {function=} setupFn
*/
var mixin = function(to, from, fnName) {
var mixin = function(to, from, fnName, setupFn) {
to[fnName] = function() {
if (setupFn) {
setupFn();
}
return from[fnName].apply(from, arguments);
}
};


/**
* @param {webdriver.WebDriver} webdriver
* @param {string=} opt_baseUrl A base URL to run get requests against.
Expand All @@ -36,10 +39,19 @@ var mixin = function(to, from, fnName) {
* @constructor
*/
var Protractor = function(webdriver, opt_baseUrl, opt_rootElement) {
// These functions should delegate to the webdriver instance, but should
// wait for Angular to sync up before performing the action. This does not
// include functions which are overridden by protractor below.
var methodsToSync = ['getCurrentUrl', 'getPageSource', 'getTitle'];

// Mix all other driver functionality into Protractor.
for (var foo in webdriver) {
if(!this[foo] && typeof webdriver[foo] == 'function') {
mixin(this, webdriver, foo);
for (var method in webdriver) {
if(!this[method] && typeof webdriver[method] == 'function') {
if (methodsToSync.indexOf(method) !== -1) {
mixin(this, webdriver, method, this.waitForAngular.bind(this));
} else {
mixin(this, webdriver, method);
}
}
}

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

0 comments on commit c22fc38

Please sign in to comment.