UCDL Accessibility Use Case Definition Language
Contents

Writing Accessibility Use Case Tests with @afixt/usecase-runner

Part 10: Tips and Best Practices

1. Name your files descriptively

Use 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

The "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

It'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

# Bad — fragile, slow
- wait: 3000
- locate: text "Results"

# Good — precise, fast
- wait_for: text "Results"

Keep 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

For every form, write negative cases that verify:

  • Error messages use role="alert" (verify: alert)
  • Invalid fields have aria-invalid and associated error text (verify: field_error)
  • Focus moves to the first error (verify: focus field "...")

7. Use via keyboard for critical actions

For your most important interactions, test keyboard activation separately:

- activate: button "Submit" via keyboard

8. Use screenshot at key moments

Screenshots are invaluable in reports. Capture them after errors, at visual checkpoints, or when verifying layout:

- verify: alert "Form has errors"
- screenshot: 'error-state-visible'