| name | phaser-test-seam-patterns |
| description | Comprehensive guide to Phaser game test seam usage, including discovery, common commands, troubleshooting, and best practices. Use when testing Phaser games, interacting with canvas-rendered content, or when DOM-based testing fails. Test seams are the PRIMARY method for Phaser game testing - DOM text search does not work with canvas-rendered text. |
Phaser Test Seam Patterns
Overview
Test seams (window.__TEST__) are the PRIMARY method for testing Phaser games. DOM-based interactions (text search, keyboard simulation) do not work reliably with canvas-rendered content.
Discovery
Always check for test seam before attempting DOM interactions:
if (window.__TEST__ && window.__TEST__.commands) {
} else {
}
Where to find test seams:
- Check scene
create() methods for window.__TEST__ setup
- Look for
window.__TEST__.commands in scene files
- Document discovered commands in progress.txt
Direct Property Access Patterns (Preferred)
Prefer Direct Property Checks Over Polling
PREFERRED: Use direct property checks instead of polling readiness flags
agent-browser eval "window.__TEST__?.sceneKey === 'GameScene'"
agent-browser eval "window.__TEST__?.commands?.clickStartGame"
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.ready) {
resolve(true);
} else {
setTimeout(check, 100);
}
};
check();
})
"
Why Direct Property Access is Better:
- Immediate check: No polling delay
- More reliable: Readiness flags may not be reliable
- Simpler code: No Promise chains
- Faster execution: No async overhead
Direct Property Access Examples
Example 1: Check Scene Key
agent-browser eval "window.__TEST__?.sceneKey || 'unknown'"
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.ready) {
resolve(window.__TEST__.sceneKey);
} else {
setTimeout(check, 100);
}
};
check();
})
"
Example 2: Check Command Availability
agent-browser eval "Object.keys(window.__TEST__?.commands || {}).includes('clickStartGame')"
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.ready) {
resolve('clickStartGame' in window.__TEST__.commands);
} else {
setTimeout(check, 100);
}
};
check();
})
"
Example 3: Get Game State
agent-browser eval "window.__TEST__?.gameState?.() || null"
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.ready) {
resolve(window.__TEST__.gameState());
} else {
setTimeout(check, 100);
}
};
check();
})
"
Readiness Flag Reliability
Important: window.__TEST__?.ready may not be reliable. Prefer direct property checks:
agent-browser eval "window.__TEST__?.sceneKey || false"
agent-browser eval "Object.keys(window.__TEST__?.commands || {}).length > 0"
agent-browser eval "window.__TEST__?.ready || false"
When Readiness Flags May Not Work:
- Scene transitions (flag may lag)
- Complex initialization (flag may not update)
- Test seam setup issues (flag may not be set)
Solution: Use direct property checks instead
Timeout Handling
Include timeout handling (max 5 seconds) before fallback:
check_test_seam_with_timeout() {
local max_wait=5
local elapsed=0
while [ $elapsed -lt $max_wait ]; do
if agent-browser eval "window.__TEST__?.sceneKey || false"; then
echo "Test seam available"
return 0
fi
sleep 1
elapsed=$((elapsed + 1))
done
echo "Test seam not available after $max_wait seconds"
return 1
}
If test seam isn't available after timeout:
- Document limitation in progress.txt
- Proceed with alternative verification (code review, TypeScript compilation)
- Don't wait indefinitely - test seams may not be available in all contexts
Discovery Techniques
Technique 1: Source Code Search
Search for test seam setup in source code:
grep -r "window.__TEST__" src/
grep -r "__TEST__\.commands" src/
grep -r "TestManager" src/
grep -r "create\(\)" src/scenes/
What to look for:
window.__TEST__ = { ... } - Test seam initialization
window.__TEST__.commands = { ... } - Command definitions
TestManager - Centralized test seam management
- Scene
create() methods - Where test seams are set up
Technique 2: Browser Inspection
Inspect test seam in browser:
agent-browser eval "typeof window.__TEST__ !== 'undefined'"
agent-browser eval "Object.keys(window.__TEST__?.commands || {})"
agent-browser eval "window.__TEST__?.sceneKey"
agent-browser eval "JSON.stringify(window.__TEST__, null, 2)"
Technique 3: Console Log Discovery
Use console logs to discover test seam:
agent-browser console | grep -i "test\|__TEST__"
agent-browser console | grep -i "test seam\|testmanager"
Technique 4: Framework-Specific Discovery
Phaser 3 Games:
- Check scene files for
window.__TEST__ setup
- Look for
TestManager singleton pattern
- Check
create() methods for test seam initialization
React/Web Apps:
- Check component files for test seam setup
- Look for test utilities or test helpers
- Check for test mode flags (
?test=1)
Technique 5: Unknown Test Seam API Discovery
When test seam API is unknown:
-
Inspect structure:
agent-browser eval "Object.keys(window.__TEST__ || {})"
-
List commands:
agent-browser eval "Object.keys(window.__TEST__?.commands || {})"
-
Check function signatures:
agent-browser eval "window.__TEST__?.commands?.clickStartGame?.toString()"
-
Document discovered API:
## Test Seam API Discovery
**Available Commands**:
- clickStartGame() - No parameters
- setTimer(seconds) - Takes number parameter
- gameState() - Returns object
**Documented in**: progress.txt
Graceful Degradation When Test Seams Unavailable
If test seams aren't available:
-
Document limitation:
## Test Seam Limitation
Test seam not available after 5 second timeout.
Using alternative verification: TypeScript compilation + code review.
-
Use alternative verification:
- TypeScript compilation check
- Code review
- DOM inspection (if applicable)
- Screenshot comparison
-
Proceed with caution:
- Note limitation in progress.txt
- Assess risk of incomplete verification
- Document fallback method used
Common Commands
See references/common-commands.md for a catalog of common test seam commands.
Typical commands include:
clickStartGame() - Navigate to game scene
movePlayerToExit() - Complete level
setTimer(seconds) - Manipulate timer
gameState() - Access game state
collectAnyCoin() - Test coin collection
simulateDragSlider() - Simulate dragging sliders (Settings scene)
Drag Simulation
For testing Phaser UI components that use pointer events (sliders, draggable objects), use drag simulation commands.
Quick Start:
agent-browser eval "window.__TEST__.commands.simulateDragSlider('music', 0, 1, 10)"
Why drag simulation?
- Programmatic value setting bypasses drag interaction flow
- Errors that only occur during dragging cannot be reproduced without simulation
- Tests actual pointer event handling (
pointerdown, pointermove, pointerup)
See references/drag-simulation.md for comprehensive guide to drag simulation patterns, including:
- Test seam drag commands (recommended)
- Agent-browser mouse command patterns
- Coordinate conversion considerations
- Best practices and troubleshooting
Known Issues
See references/troubleshooting.md for detailed troubleshooting.
Key issues:
sceneKey may lag on scene transitions (use console logs as fallback)
- Test seams are created per-scene in
create() method
- Wait for scene initialization before accessing test seam
Best Practices
- Use direct property access - Prefer
window.__TEST__?.sceneKey over polling window.__TEST__?.ready
- Prefer test seam over keyboard simulation - More reliable and faster
- Prefer standalone component test scenes for UI - Test Phaser UI components in dedicated scenes (one scene per component, booted via
?scene=...) rather than only on the full game/scene page; see phaser-component-test-scenes skill
- Create test seam helpers for common game actions
- Document test seam commands in progress.txt when discovered
- Use console logs as fallback when sceneKey doesn't update
- Use timeout handling - Max 5 seconds before fallback
- Discover test seam API - Use discovery techniques when API is unknown
- Graceful degradation - Use alternative verification when test seams unavailable
Workflow
- Check for
window.__TEST__ availability
- If not available, check source code for test seam setup
- Document available commands
- Use test seam commands for testing
- Use console logs as fallback verification
Resources
references/test-seam-discovery.md - How to find and use test seams
references/common-commands.md - Catalog of common test seam commands
references/drag-simulation.md - Comprehensive guide to drag simulation patterns
references/troubleshooting.md - Known issues and solutions