Recipes
Recipes for brewing great tests. 🍺
Recipes are short, real-world patterns that combine CraftDriver features into common testing workflows. Use this page as the index; each recipe has its own page so the list can grow without turning into a wall of code. New here? Start with Find Elements On The Page — every other recipe builds on knowing how to point at the thing you want.
Every snippet is verified in CI against a live example page you can open yourself, under dtopuzov.github.io/craftdriver/examples. To stay readable, a snippet shows only the code it is teaching and assumes a launched browser — unless it shows a Browser.launch(...) call itself. See the Vitest Hooks recipe for the surrounding setup.
For exact signatures, use the linked feature docs and the API reference.
Start Here
| Scenario | Use when | Recipe |
|---|---|---|
| Find elements | You're new and need to point CraftDriver at the element you want. | Find Elements On The Page |
Test Structure
| Scenario | Use when | Recipe |
|---|---|---|
| Vitest browser lifecycle | You want one browser per test file and a fresh page per test. | Use CraftDriver With Vitest Hooks |
| Login once, reuse session | Login UI is slow or noisy and most tests start signed in. | Log In Once And Reuse The Session |
| Multi-user flows | You need Alice and Bob signed in at the same time without leaking cookies. | Test Multi-User Workflows |
| Page objects | Selectors and steps are copy-pasted across tests and break together. | Organize Flows With Page Objects |
App Behavior
| Scenario | Use when | Recipe |
|---|---|---|
| Mock APIs and assert traffic | A UI flow depends on backend responses or request payloads. | Mock APIs And Assert Network Traffic |
| Time-sensitive UI | Debounces, trial banners, idle logout, or scheduled jobs make tests slow. | Test Time-Sensitive UI With The Virtual Clock |
| Mobile-specific behavior | Mobile layout depends on viewport, device headers, API config, or logs. | Test A Mobile Flow With API Mocks And Logs |
| File upload and download | A flow uploads a file, exports a report, or verifies downloaded content. | Test File Uploads And Downloads |
Quality Gates And Debugging
| Scenario | Use when | Recipe |
|---|---|---|
| Accessibility regression gate | CI should fail on serious page or component accessibility issues. | Run Accessibility Gates |
| Console and JavaScript errors | Tests should fail if the browser reports unexpected client-side errors. | Fail On Console And JavaScript Errors |
| Evidence on failure | You want a replayable trail of actions, network, logs, errors, and screenshots. | Capture Failure Evidence With Tracing |