You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/components_guide_web/templates/accessibility_first/accessibility-tree-snapshots.html.md
+80-1Lines changed: 80 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
-
# Accessibility Tree Snapshots
1
+
# Accessibility Testing in Playwright
2
+
3
+
## Accessibility tree snapshots
2
4
3
5
I usually don’t like snapshot “tests” because they don’t really test anything. Instead of documenting behaviour you want demonstrated, they take a shortcut and just save a dump of everything to disk. Also they usually capture implementation details (like the HTML tree) that should be allowed to vary as you refactor — adding or removing whitespace or a `<div>` shouldn’t affect a test.
Diff comparing the accessibility tree after making changes to the components.guide home page.
74
+
</collected-figure>
75
+
76
+
Once you have checked the diff of the accessibility tree and are happy with the results, re-run the tests and pass the option to update the snapshots:
77
+
78
+
```bash
79
+
npx playwright test -u
80
+
81
+
# Or if you prefer the longer form:
82
+
# npx playwright test --update-snapshots
83
+
```
84
+
85
+
----
86
+
87
+
## Asserting landmarks exist with Testing Library
88
+
89
+
If you’d like to go beyond snapshots, you can write tests that assert that specific [landmarks](/accessibility-first/landmarks) exist.
90
+
91
+
Here’s a test that checks for landmarks like `main`, `banner`, a `navigation` named “Main menu”, and a `search` form inside the `banner` are all visible on the page. These tests are run against the excellent MDN home page.
0 commit comments