axe test helper - to reuse accessibility test fixures. If future these can be test options/types

This commit is contained in:
Aarish
2025-05-22 22:50:05 -05:00
parent 5e327b9b59
commit 6d17cdacc1

17
helpers/axe-test.js Normal file
View File

@@ -0,0 +1,17 @@
const base = require('@playwright/test');
const AxeBuilder = require('@axe-core/playwright').default;
// Extend base test by providing "makeAxeBuilder"
//
// This new "test" can be used in multiple test files, and each of them will get
// a consistently configured AxeBuilder instance.
exports.test = base.test.extend({
makeAxeBuilder: async ({ page }, use) => {
const makeAxeBuilder = () => new AxeBuilder({ page })
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
.exclude('#commonly-reused-element-with-known-issue');
await use(makeAxeBuilder);
}
});
exports.expect = base.expect;