Bug 1654609 - [marionette] Port WebDriver:GetElementProperty and WebDriver:GetElementAttribute to JSWindowActor. r=marionette-reviewers,maja_zf

Differential Revision: https://phabricator.services.mozilla.com/D84576
This commit is contained in:
Henrik Skupin 2020-07-23 14:29:21 +00:00
Родитель 201cbd12be
Коммит 37c68db147
3 изменённых файлов: 62 добавлений и 6 удалений

Просмотреть файл

@ -75,6 +75,12 @@ class MarionetteFrameChild extends JSWindowActorChild {
case "MarionetteFrameParent:findElements":
result = await this.findElements(data);
break;
case "MarionetteFrameParent:getElementAttribute":
result = await this.getElementAttribute(data);
break;
case "MarionetteFrameParent:getElementProperty":
result = await this.getElementProperty(data);
break;
}
return { data: evaluate.toJSON(result) };
@ -121,4 +127,30 @@ class MarionetteFrameChild extends JSWindowActorChild {
const el = await element.find(container, strategy, selector, opts);
return this.seenEls.addAll(el);
}
/**
* Get the value of an attribute for the given element.
*/
async getElementAttribute(options = {}) {
const { name, webEl } = options;
const el = this.seenEls.get(webEl);
if (element.isBooleanAttribute(el, name)) {
if (el.hasAttribute(name)) {
return "true";
}
return null;
}
return el.getAttribute(name);
}
/**
* Get the value of a property for the given element.
*/
async getElementProperty(options = {}) {
const { name, webEl } = options;
const el = this.seenEls.get(webEl);
return typeof el[name] != "undefined" ? el[name] : null;
}
}

Просмотреть файл

@ -74,4 +74,18 @@ class MarionetteFrameParent extends JSWindowActorParent {
opts,
});
}
async getElementAttribute(webEl, name) {
return this.sendQuery("MarionetteFrameParent:getElementAttribute", {
name,
webEl,
});
}
async getElementProperty(webEl, name) {
return this.sendQuery("MarionetteFrameParent:getElementProperty", {
name,
webEl,
});
}
}

Просмотреть файл

@ -2253,9 +2253,14 @@ GeckoDriver.prototype.getElementAttribute = async function(cmd) {
assert.open(this.getCurrentWindow());
await this._handleUserPrompts();
let id = assert.string(cmd.parameters.id);
let name = assert.string(cmd.parameters.name);
let webEl = WebElement.fromUUID(id, this.context);
const id = assert.string(cmd.parameters.id);
const name = assert.string(cmd.parameters.name);
const webEl = WebElement.fromUUID(id, this.context);
if (MarionettePrefs.useActors) {
const actor = await this.getActor();
return actor.getElementAttribute(webEl, name);
}
switch (this.context) {
case Context.Chrome:
@ -2294,9 +2299,14 @@ GeckoDriver.prototype.getElementProperty = async function(cmd) {
assert.open(this.getCurrentWindow());
await this._handleUserPrompts();
let id = assert.string(cmd.parameters.id);
let name = assert.string(cmd.parameters.name);
let webEl = WebElement.fromUUID(id, this.context);
const id = assert.string(cmd.parameters.id);
const name = assert.string(cmd.parameters.name);
const webEl = WebElement.fromUUID(id, this.context);
if (MarionettePrefs.useActors) {
const actor = await this.getActor();
return actor.getElementProperty(webEl, name);
}
switch (this.context) {
case Context.Chrome: