Skip to content

Commit

Permalink
Fix result from new Element API commands not getting returned to asyn…
Browse files Browse the repository at this point in the history
…ctree and logged.

Also fixes a bug where the nodes from new Element API were getting resolved early due to which the following Nightwatch commands were getting added as child nodes of the last new Element API command.
  • Loading branch information
garg3133 committed Sep 2, 2024
1 parent 3728610 commit 6e547a5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,23 @@ class ScopedWebElement {

const createAction = (actions, webElement) => function () {
if (isFunction(commandName)) {
return commandName(webElement, ...args).then((result) => {
node.deferred.resolve(result);
});
return commandName(webElement, ...args);
}

return actions[commandName](webElement, ...args).then((result) => {
// eslint-disable-next-line no-prototype-builtins
node.deferred.resolve(result.hasOwnProperty('value') ? result.value : result);
});
return actions[commandName](webElement, ...args);
};

const node = this.queueAction({name: commandName, createAction});

// TODO: check what changes if we keep the original `getResult` instead of below.
node.getResult = function(result) {
// here, we resolve the node with `result.value` even if the result contains an error and status === -1
// which results in the command result to be `null` in test case as well, while the command actually failed.
// Is this expected? To return `null` result in case of failure as well?
// eslint-disable-next-line no-prototype-builtins
return result.hasOwnProperty('value') ? result.value : result;
};

return node;
}

Expand Down

0 comments on commit 6e547a5

Please sign in to comment.