Runnable JUnit 5 projects showing how to add accessibility analysis to
a Playwright Java test suite with
@axe-core/watcher. axe Watcher
wraps your Playwright Page (or BrowserContext) so scans run automatically as your existing
end-to-end tests drive the browser, then uploads the results to
axe Developer Hub.
| Example | Scenario | What it shows |
|---|---|---|
basic |
Auto analysis | The default mode — wrap the page and every interaction is analyzed automatically. |
manual-mode |
Manual mode | setAutoAnalyze(false) plus analyze() / start() / stop() to control scans. |
context-wrapping |
Context wrapping | wrapContext() so every page opened from one BrowserContext is instrumented. |
multi-page |
Multi-page | Reuse one wrapped page across several pages, flushing after each test. |
- Java 11 or newer. The axe Watcher integration itself supports Java 8+; these example projects target Java 11 source compatibility and are tested on Java 17 in CI.
- Maven. Each example is a standalone Maven project.
- A Chromium-based browser. axe Watcher loads a browser extension, which Chromium only supports
when launched via a persistent context using Chrome for
Testing, Playwright's bundled Chromium, or
a Microsoft Edge channel. Recent branded Google Chrome releases (139+) restrict the
--load-extensionflag axe Watcher relies on, so prefer Chrome for Testing or Chromium. - An axe Developer Hub API key and project ID.
-
Provide your credentials as environment variables.
SERVER_URLis optional and defaults tohttps://axe.deque.com; set it to target a different axe Developer Hub instance.export API_KEY="YOUR API KEY" export PROJECT_ID="YOUR PROJECT ID" # export SERVER_URL="https://axe.yourcompany.com"
-
Change into the example you want to run:
cd basic -
(Local runs only.) Install Playwright's bundled Chromium once. Skip this if you instead set
CHROME_BINto a Chrome for Testing (or Chromium) binary — the examples will launch that, which is how they run in CI.mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install chromium" -
Run the tests:
mvn test -
Open your project in axe Developer Hub to review the captured page states and issues.
- Headless mode. The examples run in Chromium's "new" headless mode (
setHeadless(true)with a Chromium-based channel) so they work in CI. axe Watcher's extension cannot load in Chromium's classic/default headless mode, soconfigure()rejects a plain--headlessargument, an--incognitoargument, orsetHeadless(true)without a supported channel. CallsetHeadless(false)to watch a run in a visible window. - Always
flush(). Results are only uploaded when you flush. The examples callpage.axeWatcher().flush()in an@AfterEachhook (thecontext-wrappingexample relies onBrowserContext.close(), which flushes every tracked page). - Attributing scans to a test. To trace a violation back to the test that produced it, call
page.axeWatcher().setTestContext(testFilePath, testLocation)— typically from a@BeforeEachhook using JUnit 5'sTestInfo.
For the full API and configuration reference, see the
@axe-core/watcher Java documentation.