@@ -22,21 +22,10 @@ yarn add expect-axe-playwright
22
22
23
23
## Usage
24
24
25
- ### With [ Playwright test runner] ( https://playwright.dev/docs/test-intro/ )
26
-
27
25
``` ts
28
26
// playwright.config.ts
29
27
import { expect } from ' @playwright/test'
30
- import { matchers } from ' expect-axe-playwright'
31
-
32
- expect .extend (matchers )
33
- ```
34
-
35
- ### With Jest
36
-
37
- ``` js
38
- // setup-jest.js
39
- import { matchers } from ' expect-axe-playwright'
28
+ import matchers from ' expect-axe-playwright'
40
29
41
30
expect .extend (matchers )
42
31
```
@@ -53,16 +42,17 @@ the rescue with the following features.
53
42
- Direct integration with the ` expect ` API for simplicity and better error
54
43
messaging.
55
44
- Automatic Axe script injection.
56
- - Works with pages, frames, and element handles.
57
- - Automatic promise and frame resolution.
45
+ - Auto-retry until timeout.
46
+ - Works with [ pages] , [ frames] , and [ locators] .
47
+ - HTML report with full violation details.
48
+ - Project-level option configuration.
58
49
59
50
Here are a few examples:
60
51
61
52
``` js
62
53
await expect (page).toBeAccessible () // Page
63
- await expect (page).toBeAccessible (' #foo' ) // Page + selector
64
- await expect (page .$ (' #foo' )).toBeAccessible () // Element handle
65
- await expect (page .$ (' iframe' )).toBeAccessible () // Iframe
54
+ await expect (page .locator (' #foo' )).toBeAccessible () // Locator
55
+ await expect (page .frameLocator (' iframe' )).toBeAccessible () // Frame locator
66
56
```
67
57
68
58
## API Documentation
@@ -77,24 +67,53 @@ You can test the entire page:
77
67
await expect (page).toBeAccessible ()
78
68
```
79
69
80
- Or pass a selector to test part of the page:
70
+ Or pass a locator to test part of the page:
81
71
82
72
``` js
83
- await expect (element). toBeAccessible (' #my-element' )
73
+ await expect (page . locator (' #my-element' )). toBeAccessible ( )
84
74
```
85
75
86
- Or pass a Playwright [ ElementHandle] :
76
+ #### Axe run options
77
+
78
+ You can configure options that should be passed to aXe at the project or
79
+ assertion level.
80
+
81
+ To configure a single assertion to use a different set of options, pass an
82
+ object with the desired arguments to the matcher.
87
83
88
84
``` js
89
- const element = await page .$ (' #my-element' )
90
- await expect (element).toBeAccessible ()
85
+ await expect (page).toBeAccessible ({
86
+ rules: {
87
+ ' color-contrast' : { enabled: false },
88
+ },
89
+ })
90
+ ```
91
+
92
+ To configure the entire project to use a different set of options, specify
93
+ options in ` use.axeOptions ` in your Playwright config file.
94
+
95
+ ``` ts
96
+ // playwright.config.ts
97
+ import { PlaywrightTestConfig } from ' @playwright/test'
98
+
99
+ const config: PlaywrightTestConfig = {
100
+ use: {
101
+ axeOptions: {
102
+ rules: {
103
+ ' color-contrast' : { enabled: false },
104
+ },
105
+ },
106
+ },
107
+ }
108
+
109
+ export default config
91
110
```
92
111
93
112
## Thanks
94
113
95
- - [ expect-playwright] ( https://github.com/playwright-community/expect-playwright )
96
- for the rock solid foundation for writing Playwright matchers.
97
114
- [ axe-playwright] ( https://github.com/abhinaba-ghosh/axe-playwright ) for the
98
115
inspiration and groundwork laid for using Axe with Playwright.
99
116
100
- [ elementhandle ] : https://playwright.dev/docs/api/class-elementhandle/
117
+ [ pages ] : https://playwright.dev/docs/api/class-page
118
+ [ frames ] : https://playwright.dev/docs/api/class-frame
119
+ [ locators ] : https://playwright.dev/docs/api/class-locator
0 commit comments