blob: a1c2d07e9c8eabbaf72503a4174579e586d74f68 [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
Adam Raine4515db62022-09-28 16:37:20 -070055 assert.deepStrictEqual(artifacts.ViewportDimensions, {
56 innerHeight: 640,
57 innerWidth: 360,
58 outerHeight: 640,
59 outerWidth: 360,
60 devicePixelRatio: 3,
61 });
Adam Rainebf8654c2022-09-13 13:24:07 -070062
63 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr);
64 assert.strictEqual(auditResults.length, 73);
65 assert.strictEqual(erroredAudits.length, 0);
66 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
Adam Rainebf8654c2022-09-13 13:24:07 -070067 'document-title',
68 'html-has-lang',
69 'label',
70 'meta-description',
Adam Rainebf8654c2022-09-13 13:24:07 -070071 'tap-targets',
72 ]);
73
74 // These a11y violations are not present on initial page load.
75 assert.strictEqual(lhr.audits['label'].details.items.length, 3);
76
77 // No trace was collected in snapshot mode.
78 const viewTrace = await reportEl.$('.lh-button--trace');
79 assert.strictEqual(viewTrace, null);
80 });
81});