@@ -68,9 +68,10 @@ axePlugin(urls: PluginUrls, options?: AxePluginOptions)
6868| Property | Type | Default | Description |
6969| -------------- | ----------- | ------------ | ----------------------------------------- |
7070| ` preset ` | ` AxePreset ` | ` 'wcag21aa' ` | Accessibility ruleset preset |
71+ | ` setupScript ` | ` string ` | ` undefined ` | Path to authentication setup script |
7172| ` scoreTargets ` | ` object ` | ` undefined ` | Pass/fail thresholds for audits or groups |
7273
73- See [ Presets] ( #presets ) for the list of available presets and [ Preset details ] ( #preset-details ) for what each preset includes .
74+ See [ Presets] ( #presets ) and [ Authentication ] ( #authentication ) sections below .
7475
7576## Multiple URLs
7677
@@ -92,6 +93,56 @@ axePlugin({
9293
9394URLs with higher weights contribute more to overall scores. For example, a URL with weight 3 has three times the influence of a URL with weight 1.
9495
96+ ## Authentication
97+
98+ To test login-protected pages, provide a ` setupScript ` that authenticates before analysis:
99+
100+ ``` ts
101+ axePlugin (' https://example.com/dashboard' , {
102+ setupScript: ' ./axe-setup.ts' ,
103+ });
104+ ```
105+
106+ The setup script must export a default async function that receives a Playwright ` Page ` instance:
107+
108+ ``` ts
109+ // axe-setup.ts
110+ import type { Page } from ' playwright-core' ;
111+
112+ export default async function (page : Page ): Promise <void > {
113+ await page .goto (' https://example.com/login' );
114+ await page .fill (' #username' , process .env .USERNAME );
115+ await page .fill (' #password' , process .env .PASSWORD );
116+ await page .click (' button[type="submit"]' );
117+ await page .waitForURL (' **/dashboard' );
118+ }
119+ ```
120+
121+ The script runs once before analyzing URLs. Authentication state (cookies, localStorage) is automatically shared across all URL analyses.
122+
123+ <details >
124+ <summary >Alternative: Cookie-based authentication</summary >
125+
126+ If you have a session token, you can inject it directly via cookies:
127+
128+ ``` ts
129+ // axe-setup.ts
130+ import type { Page } from ' playwright-core' ;
131+
132+ export default async function (page : Page ): Promise <void > {
133+ await page .context ().addCookies ([
134+ {
135+ name: ' session_token' ,
136+ value: process .env .SESSION_TOKEN ,
137+ domain: ' example.com' ,
138+ path: ' /' ,
139+ },
140+ ]);
141+ }
142+ ```
143+
144+ </details >
145+
95146## Presets
96147
97148Choose which accessibility ruleset to test against using the ` preset ` option:
0 commit comments