Skip to content

Commit

Permalink
resolves angular#1266 for node-webkit usage by using string concatena…
Browse files Browse the repository at this point in the history
…tion on baseUrl and destination when the baseUrl begins with file://
  • Loading branch information
mikemilano committed Aug 29, 2014
1 parent 2972e3a commit 0902a92
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var buildElementHelper = function(ptor) {
*
* @constructor
* @param {webdriver.Locator} locator An element locator.
* @param {ElementFinder=} opt_parentElementFinder The element finder previous to
* @param {ElementFinder=} opt_parentElementFinder The element finder previous to
* this. (i.e. opt_parentElementFinder.all(locator) => this)
* @return {ElementArrayFinder}
*/
Expand All @@ -97,7 +97,7 @@ var buildElementHelper = function(ptor) {
throw new Error('Locator cannot be empty');
}
this.locator_ = locator;
this.parentElementFinder_ = opt_parentElementFinder || null;
this.parentElementFinder_ = opt_parentElementFinder || null;
};

/**
Expand All @@ -108,7 +108,7 @@ var buildElementHelper = function(ptor) {
};

/**
* Returns the array of WebElements represented by this ElementArrayFinder.
* Returns the array of WebElements represented by this ElementArrayFinder.
*
* @alias element.all(locator).getWebElements()
* @return {Array.<webdriver.WebElement>}
Expand All @@ -122,7 +122,7 @@ var buildElementHelper = function(ptor) {
return parentWebElement.findElements(this.locator_);
}
} else {
var self = this;
var self = this;
return ptor.waitForAngular().then(function() {
if (self.locator_.findElementsOverride) {
return self.locator_.findElementsOverride(ptor.driver, null, ptor.rootEl);
Expand All @@ -134,7 +134,7 @@ var buildElementHelper = function(ptor) {
};

/**
* Get an element found by the locator by index. The index starts at 0.
* Get an element found by the locator by index. The index starts at 0.
* This does not actually retrieve the underlying element.
*
* @alias element.all(locator).get(index)
Expand All @@ -152,13 +152,13 @@ var buildElementHelper = function(ptor) {
*
* @param {number} index Element index.
* @return {ElementFinder} finder representing element at the given index.
*/
*/
ElementArrayFinder.prototype.get = function(index) {
return new ElementFinder(this.locator_, this.parentElementFinder_, null, index);
};

/**
* Get the first matching element for the locator. This does not actually
* Get the first matching element for the locator. This does not actually
* retrieve the underlying element.
*
* @alias element.all(locator).first()
Expand All @@ -180,7 +180,7 @@ var buildElementHelper = function(ptor) {
};

/**
* Get the last matching element for the locator. This does not actually
* Get the last matching element for the locator. This does not actually
* retrieve the underlying element.
*
* @alias element.all(locator).last()
Expand Down Expand Up @@ -228,17 +228,17 @@ var buildElementHelper = function(ptor) {
/**
* Represents the ElementArrayFinder as an array of ElementFinders.
*
* @return {Array.<ElementFinder>} Return a promise, which resolves to a list
* @return {Array.<ElementFinder>} Return a promise, which resolves to a list
* of ElementFinders specified by the locator.
*/
ElementArrayFinder.prototype.asElementFinders_ = function() {
var self = this;
var self = this;
return this.getWebElements().then(function(arr) {
var list = [];
arr.forEach(function(webElem, index) {
list.push(new ElementFinder(self.locator_, self.parentElementFinder_, null, index));
});
return list;
return list;
});
};

Expand Down Expand Up @@ -342,9 +342,9 @@ var buildElementHelper = function(ptor) {
};

/**
* Apply a filter function to each element found using the locator. Returns
* Apply a filter function to each element found using the locator. Returns
* promise of a new array with all elements that pass the filter function. The
* filter function receives the ElementFinder as the first argument
* filter function receives the ElementFinder as the first argument
* and the index as a second arg.
*
* @alias element.all(locator).filter(filterFn)
Expand All @@ -364,7 +364,7 @@ var buildElementHelper = function(ptor) {
* filteredElements[0].click();
* });
*
* @param {function(ElementFinder, number): webdriver.WebElement.Promise} filterFn
* @param {function(ElementFinder, number): webdriver.WebElement.Promise} filterFn
* Filter function that will test if an element should be returned.
* filterFn should return a promise that resolves to a boolean.
* @return {!webdriver.promise.Promise} A promise that resolves to an array
Expand All @@ -385,11 +385,11 @@ var buildElementHelper = function(ptor) {
};

/**
* Apply a reduce function against an accumulator and every element found
* Apply a reduce function against an accumulator and every element found
* using the locator (from left-to-right). The reduce function has to reduce
* every element into a single value (the accumulator). Returns promise of
* the accumulator. The reduce function receives the accumulator, current
* ElementFinder, the index, and the entire array of ElementFinders,
* every element into a single value (the accumulator). Returns promise of
* the accumulator. The reduce function receives the accumulator, current
* ElementFinder, the index, and the entire array of ElementFinders,
* respectively.
*
* @alias element.all(locator).reduce(reduceFn)
Expand All @@ -409,11 +409,11 @@ var buildElementHelper = function(ptor) {
*
* expect(value).toEqual('First Second Third ');
*
* @param {function(number, ElementFinder, number, Array.<ElementFinder>)}
* @param {function(number, ElementFinder, number, Array.<ElementFinder>)}
* reduceFn Reduce function that reduces every element into a single value.
* @param {*} initialValue Initial value of the accumulator.
* @param {*} initialValue Initial value of the accumulator.
* @return {!webdriver.promise.Promise} A promise that resolves to the final
* value of the accumulator.
* value of the accumulator.
*/
ElementArrayFinder.prototype.reduce = function(reduceFn, initialValue) {
var valuePromise = webdriver.promise.fulfilled(initialValue);
Expand All @@ -428,17 +428,17 @@ var buildElementHelper = function(ptor) {
};

/**
* The ElementFinder can be treated as a WebElement for most purposes, in
* The ElementFinder can be treated as a WebElement for most purposes, in
* particular, you may perform actions (i.e. click, getText) on them as you
* would a WebElement. ElementFinders extend Promise, and once an action
* is performed on an ElementFinder, the latest result from the chain can be
* would a WebElement. ElementFinders extend Promise, and once an action
* is performed on an ElementFinder, the latest result from the chain can be
* accessed using then. Unlike a WebElement, an ElementFinder will wait for
* angular to settle before performing finds or actions.
*
* ElementFinder can be used to build a chain of locators that is used to find
* an element. An ElementFinder does not actually attempt to find the element
* until an action is called, which means they can be set up in helper files
* before the page is available.
* an element. An ElementFinder does not actually attempt to find the element
* until an action is called, which means they can be set up in helper files
* before the page is available.
*
* @alias element(locator)
* @view
Expand All @@ -462,10 +462,10 @@ var buildElementHelper = function(ptor) {
*
* @constructor
* @param {webdriver.Locator} locator An element locator.
* @param {ElementFinder=} opt_parentElementFinder The element finder previous
* @param {ElementFinder=} opt_parentElementFinder The element finder previous
* to this. (i.e. opt_parentElementFinder.element(locator) => this)
* @param {webdriver.promise.Promise} opt_actionResult The promise which
* will be retrieved with then. Resolves to the latest action result,
* @param {webdriver.promise.Promise} opt_actionResult The promise which
* will be retrieved with then. Resolves to the latest action result,
* or null if no action has been called.
* @param {number=} opt_index The index of the element to retrieve. null means
* retrieve the only element, while -1 means retrieve the last element
Expand All @@ -478,9 +478,9 @@ var buildElementHelper = function(ptor) {
this.locator_ = locator;
this.parentElementFinder_ = opt_parentElementFinder || null;
this.opt_actionResult_ = opt_actionResult;
this.opt_index_ = opt_index;
this.opt_index_ = opt_index;

var self = this;
var self = this;
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
if(!self[fnName]) {
self[fnName] = function() {
Expand All @@ -496,7 +496,7 @@ var buildElementHelper = function(ptor) {
});

return new ElementFinder(
locator, opt_parentElementFinder,
locator, opt_parentElementFinder,
actionResult, opt_index);
};
}
Expand Down Expand Up @@ -535,7 +535,7 @@ var buildElementHelper = function(ptor) {
return new ElementFinder(subLocator, this);
};

/**
/**
* Calls to element may be chained to find an array of elements within a parent.
*
* @alias element(locator).all(locator)
Expand Down Expand Up @@ -573,7 +573,7 @@ var buildElementHelper = function(ptor) {
* expect(item.getText()).toBe('Second');
*
* @param {string} selector A css selector
* @return {ElementFinder} which identifies the located
* @return {ElementFinder} which identifies the located
* {@link webdriver.WebElement}
*/
ElementFinder.prototype.$ = function(selector) {
Expand Down Expand Up @@ -636,7 +636,7 @@ var buildElementHelper = function(ptor) {
/**
* Override for WebElement.prototype.isElementPresent so that protractor waits
* for Angular to settle before making the check.
*
*
* @see ElementFinder.isPresent
*
* @param {webdriver.Locator} subLocator Locator for element to look for.
Expand All @@ -656,11 +656,11 @@ var buildElementHelper = function(ptor) {
};

/**
* Returns the WebElement represented by this ElementFinder.
* Returns the WebElement represented by this ElementFinder.
* Throws the WebDriver error if the element doesn't exist.
* If index is null, it makes sure that there is only one underlying
* WebElement described by the chain of locators and issues a warning
* otherwise. If index is not null, it retrieves the WebElement specified by
* WebElement described by the chain of locators and issues a warning
* otherwise. If index is not null, it retrieves the WebElement specified by
* the index.
*
* @example
Expand All @@ -672,7 +672,7 @@ var buildElementHelper = function(ptor) {
* @return {webdriver.WebElement}
*/
ElementFinder.prototype.getWebElement = function() {
var self = this;
var self = this;
var callerError = new Error();
var webElementsPromise = new ElementArrayFinder(
this.locator_, this.parentElementFinder_).getWebElements();
Expand All @@ -682,7 +682,7 @@ var buildElementHelper = function(ptor) {
if (!arr.length) {
throw new Error('No element found using locator: ' + locatorMessage);
}
var index = self.opt_index_;
var index = self.opt_index_;
if (index == null) {
// index null means we make sure there is only one element
if (arr.length > 1) {
Expand All @@ -696,8 +696,8 @@ var buildElementHelper = function(ptor) {
}

if (index >= arr.length) {
throw new Error('Index out of bound. Trying to access index:' + index +
', but locator: ' + locatorMessage + ' only has ' +
throw new Error('Index out of bound. Trying to access index:' + index +
', but locator: ' + locatorMessage + ' only has ' +
arr.length + ' elements');
}
return arr[index];
Expand All @@ -722,7 +722,7 @@ var buildElementHelper = function(ptor) {
var webElement = this.getWebElement();
var evaluatedResult = webElement.getDriver().executeScript(
clientSideScripts.evaluate, webElement, expression);
return new ElementFinder(this.locator_, this.parentElementFinder_,
return new ElementFinder(this.locator_, this.parentElementFinder_,
evaluatedResult, this.opt_index_);
};

Expand All @@ -736,17 +736,17 @@ var buildElementHelper = function(ptor) {
var webElement = this.getWebElement();
var allowAnimationsResult = webElement.getDriver().executeScript(
clientSideScripts.allowAnimations, webElement, value);
return new ElementFinder(this.locator_, this.parentElementFinder_,
return new ElementFinder(this.locator_, this.parentElementFinder_,
allowAnimationsResult, this.opt_index_);
};

/**
* Access the underlying actionResult of ElementFinder. Implementation allows
* ElementFinder to be used as a webdriver.promise.Promise
* @param {function(webdriver.promise.Promise)} fn Function which takes
* @param {function(webdriver.promise.Promise)} fn Function which takes
* the value of the underlying actionResult.
*
* @return {webdriver.promise.Promise} Promise which contains the results of
* @return {webdriver.promise.Promise} Promise which contains the results of
* evaluating fn.
*/
ElementFinder.prototype.then = function(fn, errorFn) {
Expand Down Expand Up @@ -964,7 +964,7 @@ Protractor.prototype.findElements = function(locator) {
* the element is present on the page.
*/
Protractor.prototype.isElementPresent = function(locatorOrElement) {
var element = (locatorOrElement instanceof webdriver.promise.Promise) ?
var element = (locatorOrElement instanceof webdriver.promise.Promise) ?
locatorOrElement : this.element(locatorOrElement);
return element.isPresent();
};
Expand Down Expand Up @@ -1042,7 +1042,8 @@ Protractor.prototype.get = function(destination, opt_timeout) {
var timeout = opt_timeout ? opt_timeout : this.getPageTimeout;
var self = this;

destination = url.resolve(this.baseUrl, destination);
destination = this.baseUrl.indexOf('file://') === 0 ?
this.baseUrl + destination : url.resolve(this.baseUrl, destination);

if (this.ignoreSynchronization) {
return this.driver.get(destination);
Expand Down

0 comments on commit 0902a92

Please sign in to comment.