Bug 1651648 - Unify locator strategies for chrome and content r=marionette-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D83016
This commit is contained in:
Maja Frydrychowicz 2020-07-10 16:21:01 +00:00
parent e1aa2a866a
commit ab92315948
2 changed files with 9 additions and 26 deletions

View File

@ -97,6 +97,9 @@ const SUPPORTED_STRATEGIES = new Set([
element.Strategy.ClassName,
element.Strategy.Selector,
element.Strategy.ID,
element.Strategy.Name,
element.Strategy.LinkText,
element.Strategy.PartialLinkText,
element.Strategy.TagName,
element.Strategy.XPath,
]);
@ -2076,6 +2079,9 @@ GeckoDriver.prototype.findElement = async function(cmd) {
await this._handleUserPrompts();
let { using, value } = cmd.parameters;
if (!SUPPORTED_STRATEGIES.has(using)) {
throw new InvalidSelectorError(`Strategy not supported: ${using}`);
}
let startNode;
if (typeof cmd.parameters.element != "undefined") {
startNode = WebElement.fromUUID(cmd.parameters.element, this.context);
@ -2089,10 +2095,6 @@ GeckoDriver.prototype.findElement = async function(cmd) {
switch (this.context) {
case Context.Chrome:
if (!SUPPORTED_STRATEGIES.has(using)) {
throw new InvalidSelectorError(`Strategy not supported: ${using}`);
}
let container = { frame: win };
if (opts.startNode) {
opts.startNode = this.curBrowser.seenEls.get(opts.startNode);
@ -2121,6 +2123,9 @@ GeckoDriver.prototype.findElements = async function(cmd) {
await this._handleUserPrompts();
let { using, value } = cmd.parameters;
if (!SUPPORTED_STRATEGIES.has(using)) {
throw new InvalidSelectorError(`Strategy not supported: ${using}`);
}
let startNode;
if (typeof cmd.parameters.element != "undefined") {
startNode = WebElement.fromUUID(cmd.parameters.element, this.context);
@ -2134,10 +2139,6 @@ GeckoDriver.prototype.findElements = async function(cmd) {
switch (this.context) {
case Context.Chrome:
if (!SUPPORTED_STRATEGIES.has(using)) {
throw new InvalidSelectorError(`Strategy not supported: ${using}`);
}
let container = { frame: win };
if (startNode) {
opts.startNode = this.curBrowser.seenEls.get(opts.startNode);

View File

@ -86,16 +86,6 @@ addEventListener("dblclick", event.DoubleClickTracker.resetClick);
addEventListener("unload", event.DoubleClickTracker.resetClick, true);
const seenEls = new element.Store();
const SUPPORTED_STRATEGIES = new Set([
element.Strategy.ClassName,
element.Strategy.Selector,
element.Strategy.ID,
element.Strategy.Name,
element.Strategy.LinkText,
element.Strategy.PartialLinkText,
element.Strategy.TagName,
element.Strategy.XPath,
]);
Object.defineProperty(this, "capabilities", {
get() {
@ -1267,10 +1257,6 @@ function getPageSource() {
* given search strategy.
*/
async function findElementContent(strategy, selector, opts = {}) {
if (!SUPPORTED_STRATEGIES.has(strategy)) {
throw new InvalidSelectorError("Strategy not supported: " + strategy);
}
opts.all = false;
let el = await element.find(curContainer, strategy, selector, opts);
return seenEls.add(el);
@ -1281,10 +1267,6 @@ async function findElementContent(strategy, selector, opts = {}) {
* given search strategy.
*/
async function findElementsContent(strategy, selector, opts = {}) {
if (!SUPPORTED_STRATEGIES.has(strategy)) {
throw new InvalidSelectorError("Strategy not supported: " + strategy);
}
opts.all = true;
let els = await element.find(curContainer, strategy, selector, opts);
let webEls = seenEls.addAll(els);