Using with Puppeteer

See and use a fully working example in the Alfa examples repository.

The following code sets up a Puppeteer automation script and runs an accessibility audit using the Code Checker. The result is logged to the console.

import puppeteer from "puppeteer";
import { Audit, Logging } from "@siteimprove/alfa-test-utils";
import { Puppeteer } from "@siteimprove/alfa-puppeteer";

// Set up a Puppeteer instance
const browser = await puppeteer.launch();
const page = await browser.newPage();

// Navigate to the page to audit
await page.goto("http://localhost:8080");

// Get the document and turn it into a page representation that the Code Checker can work with
const document = await page.evaluateHandle(() => window.document);
const alfaPage = await Puppeteer.toPage(document);

// Run an accessiblity audit
const alfaResult = await Audit.run(alfaPage);

// Log the result of the audit
Logging.fromAudit(alfaResult).print();

browser.close();

Previous: UsageNext: Reporting