Recipe Conventions
These recipes are small, task-shaped starting points for common browser automation. Copy the closest recipe, replace its URL and selectors with the contract of your application, and keep the reliability shape intact.
Every example is marked no_run because it needs a local browser, an
application or fixture that is not part of this book, or an optional protocol
feature. The examples are otherwise complete tests. They all:
- use
WebDriver::managedfor a local browser; - locate normal page elements with
query(), stable app-owned test IDs, readable descriptions, and intentional cardinality; - wait for observable state with a query or
wait_until(), never a fixed sleep; - retain the task result so
driver.quit()is attempted after a command failure; and - assert a user-visible or protocol-visible result.
The placeholder https://example.test URLs and data-testid values describe
the application contract the recipe expects. Add those stable hooks to an app
you control. For a third-party page, replace them with the most stable semantic
selectors the real page exposes.
Choose A Recipe
- Forms And Page Content: login, search, HTML modal, and table/list assertions.
- Frames, Shadow DOM, And Files: iframe switching, shadow-root queries, and file upload.
- Failure Artifacts And Logs: screenshot-on-failure and browser/driver logs.
- CDP And BiDi: a typed Chromium cache command and a cross-browser BiDi event subscription.
For generated code, apply the copyable Reliable AI-Generated Tests checklist before accepting the result.