Skip to content

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

ScenarioUse whenRecipe
Find elementsYou're new and need to point CraftDriver at the element you want.Find Elements On The Page

Test Structure

ScenarioUse whenRecipe
Vitest browser lifecycleYou want one browser per test file and a fresh page per test.Use CraftDriver With Vitest Hooks
Login once, reuse sessionLogin UI is slow or noisy and most tests start signed in.Log In Once And Reuse The Session
Multi-user flowsYou need Alice and Bob signed in at the same time without leaking cookies.Test Multi-User Workflows
Page objectsSelectors and steps are copy-pasted across tests and break together.Organize Flows With Page Objects

App Behavior

ScenarioUse whenRecipe
Mock APIs and assert trafficA UI flow depends on backend responses or request payloads.Mock APIs And Assert Network Traffic
Time-sensitive UIDebounces, trial banners, idle logout, or scheduled jobs make tests slow.Test Time-Sensitive UI With The Virtual Clock
Mobile-specific behaviorMobile layout depends on viewport, device headers, API config, or logs.Test A Mobile Flow With API Mocks And Logs
File upload and downloadA flow uploads a file, exports a report, or verifies downloaded content.Test File Uploads And Downloads

Quality Gates And Debugging

ScenarioUse whenRecipe
Accessibility regression gateCI should fail on serious page or component accessibility issues.Run Accessibility Gates
Console and JavaScript errorsTests should fail if the browser reports unexpected client-side errors.Fail On Console And JavaScript Errors
Evidence on failureYou want a replayable trail of actions, network, logs, errors, and screenshots.Capture Failure Evidence With Tracing

Released under the MIT License.