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 Accessibility 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.
// This supposes that the server is already running.
// TODO: Replace with your own page
await page.goto("http://localhost:8080");
// Get the document and scrape it.
const document = await page.evaluateHandle(() => window.document);
const alfaPage = await Puppeteer.toPage(document);
// Run an accessibility audit.
const alfaResult = await Audit.run(alfaPage);
// Log the result of the audit
Logging.fromAudit(alfaResult).print();
browser.close();