зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1606794 - [marionette] Fixed WebDriver:TakeScreenshot to capture frame's content. r=marionette-reviewers,ato
Differential Revision: https://phabricator.services.mozilla.com/D58622 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
278b36aafb
Коммит
21c93d73d7
|
@ -377,6 +377,33 @@ GeckoDriver.prototype.sendAsync = function(name, data, commandID) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the browsing context.
|
||||||
|
*
|
||||||
|
* @param {boolean=} topContext
|
||||||
|
* If set to true use the window's top-level browsing context,
|
||||||
|
* otherwise the one from the currently selected frame. Defaults to false.
|
||||||
|
*
|
||||||
|
* @return {BrowsingContext}
|
||||||
|
* The browsing context.
|
||||||
|
*/
|
||||||
|
GeckoDriver.prototype.getBrowsingContext = async function(topContext = false) {
|
||||||
|
let browsingContext = null;
|
||||||
|
|
||||||
|
switch (this.context) {
|
||||||
|
case Context.Chrome:
|
||||||
|
browsingContext = this.getCurrentWindow().docShell.browsingContext;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Context.Content:
|
||||||
|
const id = await this.listener.getBrowsingContextId(topContext);
|
||||||
|
browsingContext = BrowsingContext.get(id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return browsingContext;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the session's current top-level browsing context.
|
* Get the session's current top-level browsing context.
|
||||||
*
|
*
|
||||||
|
@ -3003,13 +3030,9 @@ GeckoDriver.prototype.takeScreenshot = async function(cmd) {
|
||||||
// Only consider full screenshot if no element has been specified
|
// Only consider full screenshot if no element has been specified
|
||||||
full = webEl ? false : full;
|
full = webEl ? false : full;
|
||||||
|
|
||||||
let browsingContext;
|
|
||||||
let rect;
|
let rect;
|
||||||
|
|
||||||
switch (this.context) {
|
switch (this.context) {
|
||||||
case Context.Chrome:
|
case Context.Chrome:
|
||||||
browsingContext = win.docShell.browsingContext;
|
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
let el = this.curBrowser.seenEls.get(webEl, win);
|
let el = this.curBrowser.seenEls.get(webEl, win);
|
||||||
rect = el.getBoundingClientRect();
|
rect = el.getBoundingClientRect();
|
||||||
|
@ -3028,11 +3051,14 @@ GeckoDriver.prototype.takeScreenshot = async function(cmd) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Context.Content:
|
case Context.Content:
|
||||||
browsingContext = this.curBrowser.contentBrowser.browsingContext;
|
|
||||||
rect = await this.listener.getScreenshotRect({ el: webEl, full, scroll });
|
rect = await this.listener.getScreenshotRect({ el: webEl, full, scroll });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no element has been specified use the top-level browsing context.
|
||||||
|
// Otherwise use the browsing context from the currently selected frame.
|
||||||
|
const browsingContext = await this.getBrowsingContext(!webEl);
|
||||||
|
|
||||||
let canvas = await capture.canvas(
|
let canvas = await capture.canvas(
|
||||||
win,
|
win,
|
||||||
browsingContext,
|
browsingContext,
|
||||||
|
|
|
@ -535,13 +535,14 @@ function dispatch(fn) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let getPageSourceFn = dispatch(getPageSource);
|
|
||||||
let getActiveElementFn = dispatch(getActiveElement);
|
let getActiveElementFn = dispatch(getActiveElement);
|
||||||
|
let getBrowsingContextIdFn = dispatch(getBrowsingContextId);
|
||||||
let getElementAttributeFn = dispatch(getElementAttribute);
|
let getElementAttributeFn = dispatch(getElementAttribute);
|
||||||
let getElementPropertyFn = dispatch(getElementProperty);
|
let getElementPropertyFn = dispatch(getElementProperty);
|
||||||
let getElementTextFn = dispatch(getElementText);
|
let getElementTextFn = dispatch(getElementText);
|
||||||
let getElementTagNameFn = dispatch(getElementTagName);
|
let getElementTagNameFn = dispatch(getElementTagName);
|
||||||
let getElementRectFn = dispatch(getElementRect);
|
let getElementRectFn = dispatch(getElementRect);
|
||||||
|
let getPageSourceFn = dispatch(getPageSource);
|
||||||
let getScreenshotRectFn = dispatch(getScreenshotRect);
|
let getScreenshotRectFn = dispatch(getScreenshotRect);
|
||||||
let isElementEnabledFn = dispatch(isElementEnabled);
|
let isElementEnabledFn = dispatch(isElementEnabled);
|
||||||
let findElementContentFn = dispatch(findElementContent);
|
let findElementContentFn = dispatch(findElementContent);
|
||||||
|
@ -577,6 +578,7 @@ function startListeners() {
|
||||||
addMessageListener("Marionette:findElementContent", findElementContentFn);
|
addMessageListener("Marionette:findElementContent", findElementContentFn);
|
||||||
addMessageListener("Marionette:findElementsContent", findElementsContentFn);
|
addMessageListener("Marionette:findElementsContent", findElementsContentFn);
|
||||||
addMessageListener("Marionette:getActiveElement", getActiveElementFn);
|
addMessageListener("Marionette:getActiveElement", getActiveElementFn);
|
||||||
|
addMessageListener("Marionette:getBrowsingContextId", getBrowsingContextIdFn);
|
||||||
addMessageListener("Marionette:getElementAttribute", getElementAttributeFn);
|
addMessageListener("Marionette:getElementAttribute", getElementAttributeFn);
|
||||||
addMessageListener("Marionette:getElementProperty", getElementPropertyFn);
|
addMessageListener("Marionette:getElementProperty", getElementPropertyFn);
|
||||||
addMessageListener("Marionette:getElementRect", getElementRectFn);
|
addMessageListener("Marionette:getElementRect", getElementRectFn);
|
||||||
|
@ -622,6 +624,10 @@ function deregister() {
|
||||||
findElementsContentFn
|
findElementsContentFn
|
||||||
);
|
);
|
||||||
removeMessageListener("Marionette:getActiveElement", getActiveElementFn);
|
removeMessageListener("Marionette:getActiveElement", getActiveElementFn);
|
||||||
|
removeMessageListener(
|
||||||
|
"Marionette:getBrowsingContextId",
|
||||||
|
getBrowsingContextIdFn
|
||||||
|
);
|
||||||
removeMessageListener(
|
removeMessageListener(
|
||||||
"Marionette:getElementAttribute",
|
"Marionette:getElementAttribute",
|
||||||
getElementAttributeFn
|
getElementAttributeFn
|
||||||
|
@ -1286,6 +1292,24 @@ function getActiveElement() {
|
||||||
return evaluate.toJSON(el, seenEls);
|
return evaluate.toJSON(el, seenEls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current browsing context id.
|
||||||
|
*
|
||||||
|
* @param {boolean=} topContext
|
||||||
|
* If set to true use the window's top-level browsing context,
|
||||||
|
* otherwise the one from the currently selected frame. Defaults to false.
|
||||||
|
*
|
||||||
|
* @return {number}
|
||||||
|
* Id of the browsing context.
|
||||||
|
*/
|
||||||
|
function getBrowsingContextId(topContext = false) {
|
||||||
|
if (topContext) {
|
||||||
|
return content.docShell.browsingContext.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return curContainer.frame.docShell.browsingContext.id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send click event to element.
|
* Send click event to element.
|
||||||
*
|
*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче