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
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2160,22 +2160,22 @@ GeckoDriver.prototype.findElements = asy
*
* @throws {UnsupportedOperationError}
* Not available in current context.
* @throws {NoSuchWindowError}
* Top-level browsing context has been discarded.
* @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();
};
/**
* Send click event to element.
*
* @param {string} id
* Reference ID to the element that will be clicked.
*
--- a/testing/marionette/server.js
+++ b/testing/marionette/server.js
@@ -13,27 +13,27 @@ const ServerSocket = CC(
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
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,
} = Cu.import("chrome://marionette/content/error.js", {});
const {
Command,
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");
const logger = Log.repository.getLogger("Marionette");
const {KeepWhenOffline, LoopbackOnly} = Ci.nsIServerSocket;
@@ -555,17 +555,17 @@ server.TCPConnection = class {
if (!["newSession", "WebDriver:NewSession"].includes(cmd.name)) {
assert.session(this.driver);
}
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;
}
}
}
/**