static async checkScreenshot(element, name, minSimilarity) {
    // Make sure the DOM is up-to-date and layout has settled before continuing.
    // Without this delay, or with a shorter delay, we sometimes get missing
    // elements in our UITextDisplayer tests on some platforms.
    await shaka.test.Util.delay(0.1);

    // We need our own ID for Karma to look up the WebDriver connection.
    // By this point, we should have passed supportsScreenshots(), so the ID
    // should definitely be there.
    const urlParams = location.search;
    goog.asserts.assert(urlParams.includes('id='), 'No ID in URL!');

    const elementRect = element.getBoundingClientRect();
    const x = elementRect.left;
    const y = elementRect.top;
    const width = elementRect.width;
    const height = elementRect.height;

    // Furthermore, the screenshot may not be at the scale you expect.  Measure
    // the browser window size in JavaScript and communicate that to Karma, too,
    // so it can convert coordinates before cropping.  This value, as opposed to
    // document.body.getBoundingClientRect(), seems to most accurately reflect
    // the size of the screenshot area.
    const bodyWidth = window.innerWidth;
    const bodyHeight = window.innerHeight;

    // In addition to the id param from the top-level window, pass these
    // parameters to the screenshot endpoint in Karma.
    const params = {x, y, width, height, bodyWidth, bodyHeight, name};

    let paramsString = '';
    for (const k in params) {
      paramsString += '&' + k + '=' + params[k];
    }

    const buffer = await shaka.test.Util.fetch(
        '/screenshot/diff' + urlParams + paramsString);
    const json = shaka.util.StringUtils.fromUTF8(buffer);
    const similarity = /** @type {number} */(JSON.parse(json));

    // If the minimum similarity is not met, you can review the new screenshot
    // and the diff image in the screenshots folder.  Look for images that end
    // with "-new" and "-diff".  (NOTE: The diff is a pixel-wise diff for human
    // review, and is not produced with the same structural similarity
    // algorithm used to detect changes in the test.)  If cropping doesn't work
    // right, you can view the full-page screenshot in the image that ends with
    // "-full".
    expect(similarity).withContext(name).not.toBeLessThan(minSimilarity);
  }
Asks Karma to take a screenshot for us via the WebDriver connection and
compare it to the "official" screenshot for this test and platform.  Sets
an expectation that the new screenshot does not differ from the official
screenshot more than a fixed threshold.

Only works on browsers connected via WebDriver.  Use supportsScreenshots()
to filter screenshot-dependent tests.

@param {HTMLElement} element The HTML element to screenshot.  Must be
  within the bounds of the viewport.
@param {string} name An identifier for the screenshot.  Use alphanumeric
  plus dash and underscore only.
@param {number} minSimilarity A minimum similarity score between 0 and 1.
@return {!Promise}