Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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::managed for 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

For generated code, apply the copyable Reliable AI-Generated Tests checklist before accepting the result.