Bug 1250102 - Employ new element location API; r?automatedtester
MozReview-Commit-ID: K831MhwAT6X
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1899,69 +1899,71 @@ GeckoDriver.prototype.multiAction = func
* Find an element using the indicated search strategy.
*
* @param {string} using
* Indicates which search method to use.
* @param {string} value
* Value the client is looking for.
*/
GeckoDriver.prototype.findElement = function*(cmd, resp) {
+ let opts = {
+ startNode: cmd.parameters.element,
+ timeout: this.searchTimeout,
+ all: false,
+ };
+
switch (this.context) {
case Context.CHROME:
- resp.body.value = yield new Promise((resolve, reject) => {
- let win = this.getCurrentWindow();
- this.curBrowser.elementManager.find(
- {frame: win},
- cmd.parameters,
- this.searchTimeout,
- false /* all */,
- resolve,
- reject);
- }).then(null, e => { throw e; });
+ let container = {frame: this.getCurrentWindow()};
+ resp.body.value = yield this.curBrowser.elementManager.find(
+ container,
+ cmd.parameters.using,
+ cmd.parameters.value,
+ opts);
break;
case Context.CONTENT:
- resp.body.value = yield this.listener.findElementContent({
- value: cmd.parameters.value,
- using: cmd.parameters.using,
- element: cmd.parameters.element,
- searchTimeout: this.searchTimeout});
+ resp.body.value = yield this.listener.findElementContent(
+ cmd.parameters.using,
+ cmd.parameters.value,
+ opts);
break;
}
};
/**
* Find elements using the indicated search strategy.
*
* @param {string} using
* Indicates which search method to use.
* @param {string} value
* Value the client is looking for.
*/
GeckoDriver.prototype.findElements = function*(cmd, resp) {
+ let opts = {
+ startNode: cmd.parameters.element,
+ timeout: this.searchTimeout,
+ all: true,
+ };
+
switch (this.context) {
case Context.CHROME:
- resp.body = yield new Promise((resolve, reject) => {
- let win = this.getCurrentWindow();
- this.curBrowser.elementManager.find(
- {frame: win},
- cmd.parameters,
- this.searchTimeout,
- true /* all */,
- resolve,
- reject);
- }).then(null, e => { throw new NoSuchElementError(e.message); });
+ let container = {frame: this.getCurrentWindow()};
+ resp.body = yield this.curBrowser.elementManager.find(
+ container,
+ cmd.parameters.using,
+ cmd.parameters.value,
+ opts);
break;
case Context.CONTENT:
- resp.body = yield this.listener.findElementsContent({
- value: cmd.parameters.value,
- using: cmd.parameters.using,
- element: cmd.parameters.element,
- searchTimeout: this.searchTimeout});
+ resp.body = yield this.listener.findElementsContent(
+ cmd.parameters.using,
+ cmd.parameters.value,
+ opts);
break;
}
};
/** Return the active element on the page. */
GeckoDriver.prototype.getActiveElement = function*(cmd, resp) {
resp.body.value = yield this.listener.getActiveElement();
};
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -1266,42 +1266,36 @@ function refresh(msg) {
};
addEventListener("DOMContentLoaded", listen, false);
}
/**
* Find an element in the current browsing context's document using the
* given search strategy.
*/
-function findElementContent(opts) {
- return new Promise((resolve, reject) => {
- elementManager.find(
- curContainer,
- opts,
- opts.searchTimeout,
- false /* all */,
- resolve,
- reject);
- });
+function findElementContent(strategy, selector, opts = {}) {
+ opts.all = false;
+ return elementManager.find(
+ curContainer,
+ strategy,
+ selector,
+ opts);
}
/**
* Find elements in the current browsing context's document using the
* given search strategy.
*/
-function findElementsContent(opts) {
- return new Promise((resolve, reject) => {
- elementManager.find(
- curContainer,
- opts,
- opts.searchTimeout,
- true /* all */,
- resolve,
- reject);
- });
+function findElementsContent(strategy, selector, opts = {}) {
+ opts.all = true;
+ return elementManager.find(
+ curContainer,
+ strategy,
+ selector,
+ opts);
}
/**
* Find and return the active element on the page.
*
* @return {WebElement}
* Reference to web element.
*/