77 / 168 · 01 Agent Skills for Browser Automation · Test Patterns for AI-Driven Browser Automation← prev⊞ allnext →☰ Read as one page
11.3Pattern 2: Form Validation Testing
Test that forms reject invalid input correctly.
Example: Registration Form
# Test: empty form submission
playwright-cli goto https://app.example.com/register
playwright-cli snapshot
# → textbox "Email" [ref=e3], textbox "Password" [ref=e4], button "Create account" [ref=e5]
playwright-cli click e5 # Submit empty form
playwright-cli snapshot
# → Agent verifies alerts in YAML: "Email is required", "Password is required"
# Test: invalid email
playwright-cli fill e3 "not-an-email"
playwright-cli click e5
playwright-cli snapshot
# → Agent verifies: "Please enter a valid email"
# Test: weak password
playwright-cli fill e3 "valid@test.com"
playwright-cli fill e4 "123"
playwright-cli click e5
playwright-cli snapshot
# → Agent verifies: "Password must be at least 8 characters"
# Test: valid submission
playwright-cli fill e3 "valid@test.com"
playwright-cli fill e4 "StrongP@ss123"
playwright-cli click e5
playwright-cli snapshot
# → Agent verifies: "Registration successful"
Agent's Added Value
The agent can generate test cases from the form structure:
- Read the snapshot to enumerate every field, its role, and its accessible name
- Generate boundary-value tests automatically
- Verify error messages match expected UX copy
(For a whole suite of such cases, this is exactly the planner → generator hand-off from the Test Agents chapter — the agent explores, writes a Markdown plan, and generated .spec.ts files do the repetitive execution.)