Instructions for Playwright Test and JavaScript
Configuring your tests with Playwright Test and JavaScript
-
In the root level of your testing folder, install the
@axe-core/watcherpackage and all of its dependencies usingnpmor your preferred package manager (for example,yarnorpnpm).npm install --save-dev @axe-core/watcher -
Create a
fixtures.jsfile alongside your existing Playwright Test tests. In this file, import theplaywrightTest()function from@axe-core/watcher/playwright-test:const { playwrightTest } = require('@axe-core/watcher/playwright-test') const ACCESSIBILITY_API_KEY = process.env.ACCESSIBILITY_API_KEY const PROJECT_ID = process.env.PROJECT_ID module.exports = playwrightTest({ axe: { apiKey: ACCESSIBILITY_API_KEY, projectId: PROJECT_ID }, headless: false, // Any other Playwright configuration you’d pass to chromium.launchPersistentContext() here })Be sure to set
ACCESSIBILITY_API_KEYandPROJECT_IDin your environment to your personal API key (found in your axe Account, API KEYS tab) and your project ID (shown at the top of these instructions when you created your project or available from the Projects page by choosing Configure project under Settings). -
In your test files, replace the imports for
testandexpectfrom Playwright Test with yourfixtures.jsfile:const { test, expect } = require('@playwright/test') // Becomes: const { test, expect } = require('./fixtures') -
You're all done.
