Bug 1243415 - Add support to take full screenshots in chrome scope. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 07 Dec 2016 17:38:14 +0100
changeset 454206 543e603b1cecc1f94753de08f9e6cc38e9f33663
parent 454205 e6b3e73db93fbd233b9af327009deaebfa5fc402
child 454207 de2ba48480b1cab955a908cd51b3ddcd748bece5
push id39865
push userbmo:hskupin@gmail.com
push dateWed, 28 Dec 2016 14:56:14 +0000
bugs1243415
milestone53.0a1
Bug 1243415 - Add support to take full screenshots in chrome scope. MozReview-Commit-ID: 1FmWTEZzt7
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2389,39 +2389,58 @@ GeckoDriver.prototype.clearImportedScrip
  *
  * If called in the chrome context, the screenshot will always represent the
  * entire viewport.
  *
  * @param {string} id
  *     Reference to a web element.
  * @param {string} highlights
  *     List of web elements to highlight.
+ * @param {boolean} full
+ *     True to take a screenshot of the entire document element. Is not
+ *     considered if {@code id} is not defined. Defaults to true.
  * @param {boolean} hash
  *     True if the user requests a hash of the image data.
  *
  * @return {string}
  *     If {@code hash} is false, PNG image encoded as base64 encoded string. If
  *     'hash' is True, hex digest of the SHA-256 hash of the base64 encoded
  *     string.
  */
 GeckoDriver.prototype.takeScreenshot = function (cmd, resp) {
   let {id, highlights, full, hash} = cmd.parameters;
   highlights = highlights || [];
 
   switch (this.context) {
     case Context.CHROME:
+      let canvas;
       let container = {frame: this.getCurrentWindow()};
       let highlightEls = [];
 
       for (let h of highlights) {
         let el = this.curBrowser.seenEls.get(h, container);
         highlightEls.push(el);
       }
 
-      let canvas = capture.viewport(this.getCurrentWindow(), highlightEls);
+      // viewport
+      if (!id && !full) {
+        canvas = capture.viewport(container.frame, highlightEls);
+
+      // element or full document element
+      } else {
+        let node;
+        if (id) {
+          node = this.curBrowser.seenEls.get(id, container);
+        } else {
+          node = container.frame.document.documentElement;
+        }
+
+        canvas = capture.element(node, highlightEls);
+      }
+
       if (hash) {
         return capture.toHash(canvas);
       } else {
         return capture.toBase64(canvas);
       }
 
     case Context.CONTENT:
       if (hash) {