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
๐บ Related Episodes
- Episode 8: Advanced Statuslines and Usage Tracking
- Episode 7: Multi-Agent Workflows
- Episode 6: Programmatic Videos with Remotion
๐ฌ Get Help
- GitHub Issues: Report bugs or request features
- X/Twitter: @chongdashu
- Website: aioriented.dev
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