Test-Driven Development with Browserbase, Stagehand and Claude Code

August 29, 2025 ยท View on GitHub

๐ŸŽ“ AI Insiders Club Edition

๐Ÿค– Sponsored by Browserbase: Sign up today โ–บ https://browserbase.plug.dev/ekNRhob

๐ŸŽฅ Watch the Episode โ–บ How to Reduce 90% of Errors with Claude Code

Get Builder Pack โ–บ Click Here

Welcome Insiders! This enhanced repository contains exclusive learning materials and the complete test suite from Episode 9. Learn how to reduce 90% of errors using Test-Driven Development with AI-powered testing and Stagehand's natural language testing framework.

๐Ÿ“ฆ Repository Structure

browserbase-claude-code-stagehand/
โ”œโ”€โ”€ README.md                          # This file
โ”œโ”€โ”€ CLAUDE.md                          # Claude Code guidance file
โ”œโ”€โ”€ LESSON.md                          # ๐ŸŽ“ INSIDERS EXCLUSIVE: Complete learning guide
โ”œโ”€โ”€ PRD.md                             # ๐ŸŽ“ INSIDERS EXCLUSIVE: Product requirements document
โ”œโ”€โ”€ .claude/                           # Claude Code configuration
โ”‚   โ”œโ”€โ”€ agents/                        # AI agent definitions
โ”‚   โ”‚   โ””โ”€โ”€ stagehand-expert.md       # Stagehand testing specialist agent
โ”‚   โ”œโ”€โ”€ commands/                      # Custom commands
โ”‚   โ”‚   โ””โ”€โ”€ agent_prompts/            # Agent prompt templates
โ”‚   โ”‚       โ””โ”€โ”€ stagehand_expert_prompt.md
โ”‚   โ””โ”€โ”€ output-styles/                 # Output formatting rules
โ”‚       โ””โ”€โ”€ pragmatic-test-driven-developer.md  # TDD enforcement style
โ””โ”€โ”€ my-app/
    โ””โ”€โ”€ tests/                         # Complete test suite implementations
        โ”œโ”€โ”€ README.md                  # Comprehensive test documentation
        โ”œโ”€โ”€ playwright/                # Traditional selector-based tests
        โ”‚   โ”œโ”€โ”€ baseline.spec.ts      # Basic structure & element presence
        โ”‚   โ”œโ”€โ”€ interactions.spec.ts  # User interactions & validations
        โ”‚   โ””โ”€โ”€ color-mixer.spec.ts   # Full workflow tests
        โ””โ”€โ”€ stagehand/                 # AI-powered natural language tests
            โ”œโ”€โ”€ baseline-stagehand.spec.ts      # AI element discovery
            โ”œโ”€โ”€ interactions-stagehand.spec.ts  # Natural language interactions
            โ””โ”€โ”€ color-workflows.spec.ts         # Complex AI workflows

๐Ÿš€ Quick Start

1. Set Up Claude Code Configuration

Copy everything from .claude into the root of your Claude Code project:

cp -r .claude/* /path/to/your/project/.claude/

2. Use the Stagehand Expert Agent

Tag @agent-stagehand-expert in any task related to writing or running tests. This agent specializes in:

  • Creating executable Stagehand test files
  • Implementing hybrid AI + data-testid strategies
  • Handling LOCAL vs BROWSERBASE modes
  • Building robust tests with fallback strategies

3. Enable TDD Output Style

Run /output-style and select "Pragmatic Test Driven Developer" to enforce the Red โ†’ Green โ†’ Verify cycle automatically in your development workflow.

4. Run Example Tests

# Run Playwright tests
npx playwright test tests/playwright/

# Run Stagehand tests
npx playwright test tests/stagehand/

๐Ÿ“š What's Included

๐ŸŽ“ INSIDERS EXCLUSIVE Content

Complete Learning Guide (LESSON.md)

  • Detailed timestamps from the episode
  • Code-along exercises with solutions
  • Advanced Stagehand techniques breakdown
  • Multi-agent workflow patterns
  • Practice exercises and community challenges

Product Requirements Document (PRD.md)

  • Complete specifications for the Color Mixer app
  • User stories and acceptance criteria
  • Technical requirements and constraints
  • Perfect for practicing TDD implementation

Full Test Suite (my-app/tests/)

  • Complete working Playwright tests (3 files)
  • Complete Stagehand AI tests (3 files)
  • Side-by-side comparisons showing 70% code reduction
  • Real patterns you can adapt to your projects

Core Resources (Also in Free Version)

Stagehand Expert Agent (.claude/agents/stagehand-expert.md)

  • Complete agent definition for AI-powered testing
  • Pre-configured with Stagehand best practices
  • Natural language test patterns and examples
  • Works with Claude Code multi-agent workflows

TDD Output Style (.claude/output-styles/pragmatic-tdd-developer.md)

  • Enforces test-first development methodology
  • Automatic Red โ†’ Green โ†’ Verify cycle
  • Prevents skipping tests or writing untested code
  • Compatible with all Claude Code agents

๐ŸŽฏ Additional Resources

You're Already an Insider! ๐ŸŽ‰

As an AI Insiders Club member, you have access to:

  • โœ… This complete repository with LESSON.md
  • โœ… Custom command structures (/dev:design-app, /dev:implement-mvp)

Upgrade to Builder Pack (Premium)

Take your skills further with the complete implementation:

  • ๐Ÿš€ Full Agent Team (UI Designer, shadcn Expert, Orchestrator, TypeScript Specialist)
  • ๐Ÿš€ Complete Design Outputs (wireframes, manifest, implementation plan)
  • ๐Ÿš€ Source code for the working Color Mixer app (working app with all tests passing)

Get Builder Pack โ–บ Click Here

๐Ÿ”ง TDD Methodology Overview

The Test-Driven Development cycle demonstrated in this episode:

1. RED PHASE (Write Test)
   โ””โ”€โ”€ Write test for desired functionality
   โ””โ”€โ”€ Run test to confirm it fails
   โ””โ”€โ”€ State: "โŒ Test written and failing"

2. GREEN PHASE (Implement Code)
   โ””โ”€โ”€ Write minimal code to pass test
   โ””โ”€โ”€ No extra features or additions
   โ””โ”€โ”€ State: "โœ… Test passing"

3. VERIFY PHASE (Check Results)
   โ””โ”€โ”€ Run all tests to ensure nothing broke
   โ””โ”€โ”€ Manual verification if needed
   โ””โ”€โ”€ State: "โœ… Ready for next feature"

๐Ÿค Contributing

This repository contains the free resources from Episode 9. Contributions welcome:

  • Bug fixes in test examples
  • Additional Stagehand patterns
  • Documentation improvements
  • Translation contributions

Please open an issue first to discuss major changes.

๐Ÿ“„ License

MIT License - See LICENSE file for details

๐Ÿ™ Acknowledgments

  • Browserbase for sponsoring this episode and creating Stagehand
  • Claude Code Community for feedback and testing
  • Anthropic for TDD best practices documentation

๐Ÿ’ฌ Get Help


Remember: The best way to reduce errors isn't to write more code - it's to write tests first! ๐Ÿงช

Start with Stagehand today โ–บ https://browserbase.plug.dev/ekNRhob