From 698252c14fd169c06034fbaddf436ef6fc69b19b Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Fri, 24 Nov 2017 16:20:21 +0000 Subject: [PATCH] Bug 1420431 - Allow WebElement to be returned from GeckoDriver. r=maja_zf Instead of having to assign resp.body.value explicitly when dealing with WebElements, this makes it possible to return WebElement references directly from GeckoDriver command handlers. This was not possible in the past because web element representations were just plain object literals. MozReview-Commit-ID: EPqXJ2gpNen --- testing/marionette/driver.js | 4 ++-- testing/marionette/server.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index 1029895cda29..8a044210de03 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -2171,12 +2171,12 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) { * @throws {UnexpectedAlertOpenError} * A modal dialog is open, blocking this operation. */ -GeckoDriver.prototype.getActiveElement = async function(cmd, resp) { +GeckoDriver.prototype.getActiveElement = async function() { assert.content(this.context); assert.window(this.getCurrentWindow()); this._assertAndDismissModal(); - resp.body.value = await this.listener.getActiveElement(); + return this.listener.getActiveElement(); }; /** diff --git a/testing/marionette/server.js b/testing/marionette/server.js index 118748be8e5d..8a71c0fcd03e 100644 --- a/testing/marionette/server.js +++ b/testing/marionette/server.js @@ -18,6 +18,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("chrome://marionette/content/assert.js"); const {GeckoDriver} = Cu.import("chrome://marionette/content/driver.js", {}); +const {WebElement} = Cu.import("chrome://marionette/content/element.js", {}); const { error, UnknownCommandError, @@ -27,8 +28,7 @@ const { Message, Response, } = Cu.import("chrome://marionette/content/message.js", {}); -const {DebuggerTransport} = - Cu.import("chrome://marionette/content/transport.js", {}); +const {DebuggerTransport} = Cu.import("chrome://marionette/content/transport.js", {}); XPCOMUtils.defineLazyServiceGetter( this, "env", "@mozilla.org/process/environment;1", "nsIEnvironment"); @@ -560,7 +560,7 @@ server.TCPConnection = class { let rv = await fn.bind(this.driver)(cmd, resp); if (typeof rv != "undefined") { - if (typeof rv != "object") { + if (rv instanceof WebElement || typeof rv != "object") { resp.body = {value: rv}; } else { resp.body = rv;