blob: a0df209d9e379750d9176085a27a72da9d274120 [file] [log] [blame]
Adam Rainebf8654c2022-09-13 13:24:07 -07001// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6
7import {expectError} from '../../conductor/events.js';
8import {getBrowserAndPages} from '../../shared/helper.js';
9import {describe, it} from '../../shared/mocha-extensions.js';
10import {
11 clickStartButton,
12 getAuditsBreakdown,
13 navigateToLighthouseTab,
14 selectMode,
15 waitForResult,
16} from '../helpers/lighthouse-helpers.js';
17
18// This test will fail (by default) in headful mode, as the target page never gets painted.
19// To resolve this when debugging, just make sure the target page is visible during the lighthouse run.
20
21describe('Snapshot', async function() {
22 // The tests in this suite are particularly slow
23 this.timeout(60_000);
24
25 beforeEach(() => {
26 // https://bugs.chromium.org/p/chromium/issues/detail?id=1357791
27 expectError(/Protocol Error: the message with wrong session id/);
28 expectError(/Protocol Error: the message with wrong session id/);
29 expectError(/Protocol Error: the message with wrong session id/);
30 expectError(/Protocol Error: the message with wrong session id/);
31 expectError(/Protocol Error: the message with wrong session id/);
32 });
33
34 it('successfully returns a Lighthouse report for the page state', async () => {
35 await navigateToLighthouseTab('lighthouse/hello.html');
36
37 const {target} = await getBrowserAndPages();
38 await target.evaluate(() => {
39 const makeTextFieldBtn = document.querySelector('button');
40 if (!makeTextFieldBtn) {
41 throw new Error('Button not found');
42 }
43 makeTextFieldBtn.click();
44 makeTextFieldBtn.click();
45 makeTextFieldBtn.click();
46 });
47
48 await selectMode('snapshot');
49 await clickStartButton();
50
51 const {lhr, artifacts, reportEl} = await waitForResult();
52
53 assert.strictEqual(lhr.gatherMode, 'snapshot');
54
55 const {innerWidth, innerHeight, outerWidth, outerHeight, devicePixelRatio} = artifacts.ViewportDimensions;
56 // This value can vary slightly, depending on the display.
57 // https://bugs.chromium.org/p/chromium/issues/detail?id=1346355
58 assert.approximately(innerHeight, 1742, 1);
59 assert.strictEqual(innerWidth, 980);
60 assert.strictEqual(outerWidth, 360);
61 assert.strictEqual(outerHeight, 640);
62 assert.strictEqual(devicePixelRatio, 3);
63
64 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr);
65 assert.strictEqual(auditResults.length, 73);
66 assert.strictEqual(erroredAudits.length, 0);
67 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
68 'viewport',
69 'document-title',
70 'html-has-lang',
71 'label',
72 'meta-description',
73 'font-size',
74 'tap-targets',
75 ]);
76
77 // These a11y violations are not present on initial page load.
78 assert.strictEqual(lhr.audits['label'].details.items.length, 3);
79
80 // No trace was collected in snapshot mode.
81 const viewTrace = await reportEl.$('.lh-button--trace');
82 assert.strictEqual(viewTrace, null);
83 });
84});