From 6e547a59a725371f78aa572d62757d5fa8525d08 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Mon, 2 Sep 2024 22:29:44 +0530 Subject: [PATCH] Fix result from new Element API commands not getting returned to asynctree 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. --- lib/api/web-element/scoped-element.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 35209164a..3ada4a627 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -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; }