From bb7dc5a696420114fb2b87507e8e7884d959245c Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Wed, 27 Mar 2024 03:44:40 +0530 Subject: [PATCH 1/2] fix terminal commands now return selenium result --- lib/api/web-element/commands/sendKeys.js | 2 +- lib/api/web-element/scoped-element.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/api/web-element/commands/sendKeys.js b/lib/api/web-element/commands/sendKeys.js index a39415e10..1fc12af07 100644 --- a/lib/api/web-element/commands/sendKeys.js +++ b/lib/api/web-element/commands/sendKeys.js @@ -35,6 +35,6 @@ module.exports.command = function (...args) { }, []); return this.runQueuedCommand('sendKeysToElement', { - args: [keys] + args: [keys], isTerminal: true }); }; diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 35209164a..07e3b47c4 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -260,12 +260,15 @@ class ScopedWebElement { /** * Keeps in sync operation sequence produced by methods. */ - waitFor(promise, {isRoot = false} = {}) { + waitFor(promise, {isRoot = false, isTerminal = false} = {}) { if (isRoot) { this.webElement = promise; } else { this.webElement = new WebElementPromise(this.driver, this.then(async (element) => { - await promise; + const result = await promise; + if (isTerminal && result && result.status === -1) { + return result.error; + } return element; })); @@ -293,8 +296,12 @@ class ScopedWebElement { } return actions[commandName](webElement, ...args).then((result) => { + if (result && result.status === -1) { + node.deferred.resolve(result); + } else { // eslint-disable-next-line no-prototype-builtins - node.deferred.resolve(result.hasOwnProperty('value') ? result.value : result); + node.deferred.resolve(result.hasOwnProperty('value') ? result.value : result); + } }); }; @@ -303,14 +310,14 @@ class ScopedWebElement { return node; } - runQueuedCommand(commandName, {args = [], namespace, isRoot = false, name} = {}) { + runQueuedCommand(commandName, {args = [], namespace, isRoot = false, isTerminal = false, name} = {}) { const node = this.createNode(commandName, args, namespace); if (name) { node.name = name; } - return this.waitFor(node.deferred.promise, {isRoot}); + return this.waitFor(node.deferred.promise, {isRoot, isTerminal}); } queueAction({name, createAction, namespace = 'element()', args = [], rejectPromise = true} = {}) { From 0c45852d7c2fd0944e97d655515a1b36b81209af Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Sun, 19 May 2024 18:06:54 +0530 Subject: [PATCH 2/2] removed isterminal flag --- lib/api/web-element/commands/sendKeys.js | 2 +- lib/api/web-element/scoped-element.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/api/web-element/commands/sendKeys.js b/lib/api/web-element/commands/sendKeys.js index 1fc12af07..a39415e10 100644 --- a/lib/api/web-element/commands/sendKeys.js +++ b/lib/api/web-element/commands/sendKeys.js @@ -35,6 +35,6 @@ module.exports.command = function (...args) { }, []); return this.runQueuedCommand('sendKeysToElement', { - args: [keys], isTerminal: true + args: [keys] }); }; diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index 07e3b47c4..b6daa7e66 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -6,6 +6,7 @@ const {ShadowRoot} = require('selenium-webdriver/lib/webdriver'); const {Logger, isFunction, createPromise} = require('../../utils/'); const {WEB_ELEMENT_ID} = require('../../transport/selenium-webdriver/session.js'); const {ScopedElementLocator} = require('./element-locator.js'); +const {error} = require('console'); class ScopedWebElement { @@ -260,14 +261,18 @@ class ScopedWebElement { /** * Keeps in sync operation sequence produced by methods. */ - waitFor(promise, {isRoot = false, isTerminal = false} = {}) { + waitFor(promise, {isRoot = false} = {}) { if (isRoot) { this.webElement = promise; } else { this.webElement = new WebElementPromise(this.driver, this.then(async (element) => { const result = await promise; - if (isTerminal && result && result.status === -1) { - return result.error; + if (result && result.status === -1) { + return { + 'error': result.error.name, + 'message': result.error.message, + 'stack': result.error.stack + }; } return element; @@ -310,14 +315,14 @@ class ScopedWebElement { return node; } - runQueuedCommand(commandName, {args = [], namespace, isRoot = false, isTerminal = false, name} = {}) { + runQueuedCommand(commandName, {args = [], namespace, isRoot = false, name} = {}) { const node = this.createNode(commandName, args, namespace); if (name) { node.name = name; } - return this.waitFor(node.deferred.promise, {isRoot, isTerminal}); + return this.waitFor(node.deferred.promise, {isRoot}); } queueAction({name, createAction, namespace = 'element()', args = [], rejectPromise = true} = {}) {