Skip to content

Integration with playwright? #143

@vincerubinetti

Description

@vincerubinetti

I use https://www.npmjs.com/package/axe-playwright to run my tests, which requires you to do...

import { injectAxe, getViolations} from 'axe-playwright'

await injectAxe(page);
await configureAxe(page, { rules, checks });
const violations = await getViolations(page);

Perhaps it would be enough to export rules and checks from this library so we could use them.

Edit 1

I tried to figure out how to get the rules and checks this plugin has registered back from axe core, like axe.getRules() or axe._audit.data.checks or axe._audit.checks, but I've had no luck.

Edit 2

More info. I tried patching this package in my node_modules to return the rules and checks. When passing them to axe-playwright, I get the following error:

Error: Unexpected value

  53 |     /** setup axe */
  54 |     await injectAxe(page);
> 55 |     await configureAxe(page, { rules, checks });
     |           ^
  56 |
  57 |     /** axe check */
  58 |     const check = async () => {

    at /Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/axe-playwright/dist/index.js:64:16
    at /Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/axe-playwright/dist/index.js:31:71
    at __awaiter (/Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/axe-playwright/dist/index.js:27:12)
    at configureAxe (/Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/axe-playwright/dist/index.js:63:45)
    at /Users/vincerubinetti/Desktop/molevolvr2.0/frontend/tests/accessibility.spec.ts:55:11

Edit 3

I tried switching from axe-playwright to @axe-core/playwright, and am still running into an issue:

Error: Unexpected value

  53 |     /** axe check */
  54 |     const check = async () => {
> 55 |       const { violations } = await new AxeBuilder({ page })
     |                              ^
  56 |         .options({ rules, checks })
  57 |         .analyze();
  58 |       expect(violations).toStrictEqual([]);

    at AxeBuilder.runPartialRecursive (/Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/@axe-core/playwright/dist/index.mjs:283:34)
    at AxeBuilder.analyze (/Users/vincerubinetti/Desktop/molevolvr2.0/frontend/node_modules/@axe-core/playwright/dist/index.mjs:210:28)
    at check (/Users/vincerubinetti/Desktop/molevolvr2.0/frontend/tests/accessibility.spec.ts:55:30)
    at /Users/vincerubinetti/Desktop/molevolvr2.0/frontend/tests/accessibility.spec.ts:61:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions