Automated E2E testing framework for a shopping cart web app using Claude Code and Playwright.
- Runs a simple Node.js shopping cart app (the "Soup Shop")
- Uses Claude Code as an autonomous test agent to interact with the app via Playwright
- Tests login, adding items to cart, checkout flows, and error handling
Write tests in plain English - describe what you want to test and how to validate it:
{
"name": "checkout-success",
"prompt": "add Clam Chowder to cart, go to checkout, fill name 'John Doe' and address '123 Main St'",
"validation": "Verify the success page shows 'Order Confirmed' with an order ID"
}The framework uses natural language for both the test action (prompt) and the pass/fail criteria (validation). No page objects, selectors, or test code required.
All commands and agents use Claude Haiku to minimize API costs while maintaining reliable test execution. Haiku is well-suited for structured automation tasks like form filling, button clicking, and page verification.
- Claude Code installed (
npm install -g @anthropic-ai/claude-code)
# Clone and enter the repo,
# Run the setup command in Claude Code
claude
/init-cartThe /init-cart command will:
- Check and install all other prerequisites (Node.js, npm, Python)
- Set up environment files
- Start the shopping cart app
- Optionally run a test
Single test via Claude command:
/cart-test add Mulligatawny Soup to cart
All tests via Python (parallel):
python3 run_tests.py --parallel 3 --verboseRun specific tests:
python3 run_tests.py --filter checkout-success
python3 run_tests.py --filter "add-item-to-cart,checkout-success"With --verbose, you can inspect detailed output in the results/ directory:
{test-name}.log- Full execution log for each test{test-name}-mcp.json- Per-session MCP config (browser profile isolation)summary.json- Aggregated results with pass/fail counts and durations
Playwright MCP doesn't support parallel testing by default (issue #893).
We work around this by creating a separate browser session per test worker:
- Each parallel worker gets a unique
--user-data-dir(/tmp/playwright-e2e-worker-{N}) - A per-test MCP config is generated in
results/{test-name}-mcp.json
This allows running multiple tests concurrently without session conflicts.
Login is handled by a dedicated login subagent (.claude/agents/login.md) with two key security properties:
-
Context isolation - The login subagent runs with no context from the parent request. This reduces token usage and prevents credential leakage into the main conversation.
-
Secret injection via Playwright MCP - Credentials never appear in the LLM context. The
--secretsflag in.mcp.jsonpoints to.env.e2e-secrets:"--secrets", ".env.e2e-secrets"
The agent uses placeholder values (
SHOP_USERNAME,SHOP_PASSWORD) inbrowser_typecalls, and Playwright MCP substitutes them with actual values from the secrets file at execution time.
This architecture ensures credentials are handled securely without being exposed to any LLM context.
| Test | Description |
|---|---|
| view-cart | Verify cart page loads with soups |
| add-item-to-cart | Add soup and verify it's in cart |
| checkout-success | Complete checkout flow |
| checkout-no-soup-for-you | Test the "No soup for you!" Easter egg |
| remove-item-from-cart | Add then remove item |
| multiple-items-checkout | Checkout with multiple items |