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

Commit

Permalink
fix(protractor) fix stack traces for WebElement errors
Browse files Browse the repository at this point in the history
When 3c0e727
refactored `element()` into the ElementFinder object, the function lost
some of its error handling.  This removed references to frames inside
tests (`it()` blocks), making it hard to tell where the error was
actually occurring.

This commit fixes these problems, showing full stack traces for
WebElement errors.
  • Loading branch information
thetoothpick authored and hankduan committed Jul 17, 2014
1 parent 60df563 commit 0c4a70e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,15 @@ var buildElementHelper = function(ptor) {
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
if(!self[fnName]) {
self[fnName] = function() {
var callerError = new Error();
var args = arguments;
var webElem = self.getWebElement();
var actionResult = webElem.then(
function(webElem_) {
return webElem_[fnName].apply(webElem_, args);
return webElem_[fnName].apply(webElem_, args).then(null, function(e) {
e.stack = e.stack + '\n' + callerError.stack;
throw e;
});
});

return new ElementFinder(
Expand Down Expand Up @@ -660,6 +664,7 @@ var buildElementHelper = function(ptor) {
*/
ElementFinder.prototype.getWebElement = function() {
var self = this;
var callerError = new Error();
var webElementsPromise = new ElementArrayFinder(
this.locator_, this.parentElementFinder_).getWebElements();

Expand Down Expand Up @@ -687,6 +692,9 @@ var buildElementHelper = function(ptor) {
arr.length + ' elements');
}
return arr[index];
}).then(null, function(e) {
e.stack = e.stack + '\n' + callerError.stack;
throw e;
});
return new webdriver.WebElement(ptor.driver, id);
};
Expand Down

0 comments on commit 0c4a70e

Please sign in to comment.