Bug 1243415 - Add support to take full screenshots in chrome scope. r=automatedtester a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 07 Dec 2016 17:38:14 +0100
changeset 353304 88b2329f2448714081dd8074751fecbfdc96b3f6
parent 353303 7b31d0beacbcdad77273ab9417f75f8593a2bf99
child 353305 c509d6923794b5d065783ff8c83e84d4b613a0e8
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1243415
milestone52.0a2
Bug 1243415 - Add support to take full screenshots in chrome scope. r=automatedtester a=test-only MozReview-Commit-ID: 1FmWTEZzt7
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2358,39 +2358,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) {