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

Commit 0c4a70e

Browse files
thetoothpickhankduan
authored andcommitted
fix(protractor) fix stack traces for WebElement errors
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.
1 parent 60df563 commit 0c4a70e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/protractor.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,15 @@ var buildElementHelper = function(ptor) {
475475
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
476476
if(!self[fnName]) {
477477
self[fnName] = function() {
478+
var callerError = new Error();
478479
var args = arguments;
479480
var webElem = self.getWebElement();
480481
var actionResult = webElem.then(
481482
function(webElem_) {
482-
return webElem_[fnName].apply(webElem_, args);
483+
return webElem_[fnName].apply(webElem_, args).then(null, function(e) {
484+
e.stack = e.stack + '\n' + callerError.stack;
485+
throw e;
486+
});
483487
});
484488

485489
return new ElementFinder(
@@ -660,6 +664,7 @@ var buildElementHelper = function(ptor) {
660664
*/
661665
ElementFinder.prototype.getWebElement = function() {
662666
var self = this;
667+
var callerError = new Error();
663668
var webElementsPromise = new ElementArrayFinder(
664669
this.locator_, this.parentElementFinder_).getWebElements();
665670

@@ -687,6 +692,9 @@ var buildElementHelper = function(ptor) {
687692
arr.length + ' elements');
688693
}
689694
return arr[index];
695+
}).then(null, function(e) {
696+
e.stack = e.stack + '\n' + callerError.stack;
697+
throw e;
690698
});
691699
return new webdriver.WebElement(ptor.driver, id);
692700
};

0 commit comments

Comments
 (0)