Part 10: Tips and Best Practices
Permalink to Part 10: Tips and Best Practices1. Name your files descriptively
Permalink to 1. Name your files descriptivelyUse the pattern feature-scenario.uc.yaml:
login-success.uc.yaml
login-error-wrong-password.uc.yaml
login-error-empty-fields.uc.yaml
register-success.uc.yaml
checkout-guest-user.uc.yaml
2. Use the accessible name the user sees
Permalink to 2. Use the accessible name the user seesThe "name" in your step should match what a screen reader would announce. If
your button says "Submit" visually but has aria-label="Send form", use
"Send form".
3. Don't skip locate and focus
Permalink to 3. Don't skip locate and focusIt's tempting to just write activate: button "Submit" — Playwright will find
and click it. But adding locate and focus first tests two additional
accessibility requirements that activate alone won't catch.
4. Prefer wait_for over wait
Permalink to 4. Prefer wait_for over wait# Bad — fragile, slow
- wait: 3000
- locate: text "Results"
# Good — precise, fast
- wait_for: text "Results"
5. One use case per file
Permalink to 5. One use case per fileKeep each file focused on a single scenario. Use extension cases to create variants rather than putting multiple paths in one file.
6. Test the error experience, not just the happy path
Permalink to 6. Test the error experience, not just the happy pathFor every form, write negative cases that verify:
- Error messages use
role="alert"(verify: alert) - Invalid fields have
aria-invalidand associated error text (verify: field_error) - Focus moves to the first error (
verify: focus field "...")
7. Use via keyboard for critical actions
Permalink to 7. Use via keyboard for critical actionsFor your most important interactions, test keyboard activation separately:
- activate: button "Submit" via keyboard
8. Use screenshot at key moments
Permalink to 8. Use screenshot at key momentsScreenshots are invaluable in reports. Capture them after errors, at visual checkpoints, or when verifying layout:
- verify: alert "Form has errors"
- screenshot: 'error-state-visible'