Library › Book 1 › Test Patterns for AI-Driven Automation
Test Patterns for AI-Driven Automation
13.1🔒OverviewPatterns separate a framework from a pile of scripts. This chapter catalogs nine, in the ref-driven vocabulary of the Playwright CLI.
13.2🔒Pattern 1: Navigate-Act-Verify (NAV)The fundamental pattern. Every browser test is a variation of Navigate -> Act -> Verify:
13.3🔒Pattern 2: Form Validation TestingVerify that forms reject invalid input -- and accept valid input. Each case is a small NAV loop:
13.4🔒Pattern 3: Multi-Page FlowTests that span multiple navigations -- the e-commerce checkout is the canonical case:
13.5🔒Pattern 4: Authenticated Tests with Saved StateMost of your suite runs behind the login page, and driving the login form in every test is slow and couples the suite to the auth flow. The…
13.6🔒Pattern 5: Data Extraction and VerificationWhen you need data rather than interaction, one JavaScript expression beats parsing a snapshot. eval is the escape hatch -- and inside eval…
13.7🔒Pattern 6: Async Operations (Uploads, Debounce)Actions auto-wait for their target element. For long-running operations, poll observable state via eval or re-snapshot -- with judgment…
13.8🔒Pattern 7: Multi-Session TestingTests requiring multiple browser contexts -- two users, two roles, two environments. Each named session is an isolated browser context; one…
13.9🔒Pattern 8: Negative and Error-State TestingVerify the application rejects invalid operations and fails gracefully:
13.10🔒Pattern 9: Visual Regression (Screenshot Comparison)The disk-first advantage: a pixel-diff tool compares hundreds of PNG pairs for zero tokens; the agent reads only the images that differ…
13.11🔒Anti-PatternsDon't hard-code wait times. Actions auto-wait; for slow async state, poll via eval or re-snapshot with judgment. sleep 5 is never the…
13.12🔒Key Takeaways- Nine patterns cover most scenarios; NAV (Navigate-Act-Verify) is the fundamental one underneath all the others - Refs come from snapshots…
13.13🔒Q&ASelf-Assessment Quiz1. What does it mean that the CLI is "ref-driven," and where do refs come from? 2. In the multi-page flow pattern, what carries across…
13.14🔒Exercises[Beginner] Exercise 13.1: Implement the NAV pattern against a public demo site: open, snapshot, act on refs, verify via a second snapshot.
13.15🔒Career Translation- Implemented a nine-pattern test library for AI-driven browser automation (Navigate-Act-Verify through visual regression) on the…
13.16🔒Q&AInterview Depth CheckPrompt: You are testing a checkout flow spanning 4 pages. How do you design the test to be resilient while tracking state across pages?