| name | browser-test-seam-optimization |
| description | Optimize browser testing workflows with test seams, reducing command overhead and improving testing efficiency. Use when testing Phaser games or web applications to reduce execution time by 40-50%. Provides composite test functions, command batching, and efficient wait strategies. |
Browser Test Seam Optimization
Optimize browser testing workflows with test seams to reduce execution time by 40-50%. Reduces testing overhead from 30-60% of total time to 10-20%.
Overview
Problem: Sequential individual commands for each verification step (20-80 commands per task)
Solution: Composite test functions, command batching, and optimized wait strategies
Impact: Save 20-40 seconds per testing phase
Core Patterns
Pattern 1: Composite Test Functions
Instead of 10+ individual commands, create composite functions:
agent-browser eval "window.__TEST__.commands.clickStartGame()"
agent-browser wait 2000
agent-browser eval "window.__TEST__.commands.setTimer(5)"
agent-browser eval "window.__TEST__.commands.collectAnyCoin()"
agent-browser eval "window.__TEST__.gameState()"
window.__TEST__.commands.testPlayAgainFlow = () => {
this.scene.start('GameScene');
this.setTimer(5);
this.collectAnyCoin();
return this.gameState();
};
agent-browser eval "window.__TEST__.commands.testPlayAgainFlow()"
Common composite functions:
window.__TEST__.commands.testPlayAgainFlow = () => {
this.scene.start('GameScene');
this.setTimer(5);
this.collectAnyCoin();
return this.gameState();
};
window.__TEST__.commands.testLevelCompleteFlow = () => {
this.movePlayerToExit();
return this.gameState();
};
window.__TEST__.commands.testSceneTransition = (from, to) => {
this.scene.start(to);
return { from, to, sceneKey: this.scene.key };
};
window.__TEST__.commands.testGameStateReset = () => {
this.reset();
return this.gameState();
};
Pattern 2: Batch Independent Checks
Use Promise.all() for parallel evaluations:
agent-browser eval "window.__TEST__.gameState().score"
agent-browser eval "window.__TEST__.gameState().timer"
agent-browser eval "window.__TEST__.gameState().player.x"
agent-browser eval "
const state = window.__TEST__.gameState();
Promise.all([
Promise.resolve(state.score),
Promise.resolve(state.timer),
Promise.resolve(state.player.x)
]).then(results => ({
score: results[0],
timer: results[1],
playerX: results[2]
}))
"
Or simpler batching:
agent-browser eval "
const state = window.__TEST__.gameState();
JSON.stringify({
score: state.score,
timer: state.timer,
playerX: state.player?.x,
playerY: state.player?.y
})
"
Pattern 3: Optimize Wait Strategies
Use simple property checks instead of Promise polling:
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.ready) {
resolve(true);
} else {
setTimeout(check, 100);
}
};
check();
})
"
agent-browser eval "window.__TEST__?.ready || false"
Use timeout-based checks with max wait:
agent-browser eval "
(() => {
const maxWait = 5000;
const start = Date.now();
while (Date.now() - start < maxWait) {
if (window.__TEST__?.ready) return true;
}
return false;
})()
"
Pattern 4: Test Seam Readiness Patterns
Check window.TEST?.sceneKey directly:
agent-browser eval "
new Promise((resolve) => {
const check = () => {
if (window.__TEST__?.sceneKey === 'GameScene') {
resolve(true);
} else {
setTimeout(check, 100);
}
};
check();
})
"
agent-browser eval "window.__TEST__?.sceneKey === 'GameScene'"
Use Object.keys() for verification:
agent-browser eval "
Object.keys(window.__TEST__?.commands || {}).includes('clickStartGame')
"
Complete Optimization Examples
Example 1: Test Play Again Flow
Before (Inefficient):
agent-browser eval "window.__TEST__.commands.clickStartGame()"
agent-browser wait 2000
agent-browser eval "window.__TEST__.commands.setTimer(5)"
agent-browser eval "window.__TEST__.commands.collectAnyCoin()"
agent-browser eval "window.__TEST__.gameState().score"
agent-browser eval "window.__TEST__.gameState().timer"
After (Optimized):
agent-browser eval "
const result = window.__TEST__.commands.testPlayAgainFlow();
JSON.stringify(result)
"
Example 2: Verify State Changes
Before (Inefficient):
agent-browser eval "const before = window.__TEST__.gameState()"
agent-browser eval "window.__TEST__.commands.collectAnyCoin()"
agent-browser eval "const after = window.__TEST__.gameState()"
agent-browser eval "after.score > before.score"
After (Optimized):
agent-browser eval "
const before = window.__TEST__.gameState();
window.__TEST__.commands.collectAnyCoin();
const after = window.__TEST__.gameState();
after.score > before.score
"
Example 3: Scene Navigation Testing
Before (Inefficient):
agent-browser eval "window.__TEST__.commands.goToScene('GameScene')"
agent-browser wait 2000
agent-browser eval "window.__TEST__.sceneKey"
agent-browser eval "window.__TEST__.gameState()"
After (Optimized):
agent-browser eval "
window.__TEST__.commands.goToScene('GameScene');
setTimeout(() => {
const state = window.__TEST__.gameState();
return JSON.stringify({ scene: window.__TEST__.sceneKey, state });
}, 500)
"
Wait Strategy Optimization
Minimal Waits
Use minimal waits for known operations:
- Scene transitions: 500ms (not 2000ms)
- State checks: 100ms (not 500ms)
- DOM updates: 200ms (not 1000ms)
- Network requests: Poll until complete (not fixed wait)
agent-browser eval "window.__TEST__.commands.clickStartGame()"
agent-browser wait 2000
agent-browser eval "window.__TEST__.commands.clickStartGame()"
agent-browser wait 500
Polling Instead of Fixed Waits
Use polling with timeout instead of fixed waits:
agent-browser eval "window.__TEST__.commands.clickStartGame()"
agent-browser wait 2000
agent-browser eval "
(() => {
const maxWait = 5000;
const start = Date.now();
while (Date.now() - start < maxWait) {
if (window.__TEST__?.ready && window.__TEST__.sceneKey === 'GameScene') {
return true;
}
}
return false;
})()
"
Performance Impact
Before Optimization
- Command count: 20-80 commands per task
- Execution time: 30-60 seconds per testing phase
- Wait time: 2-5 seconds per wait operation
- Total overhead: 30-60% of task time
After Optimization
- Command count: 5-10 batched commands
- Execution time: 10-20 seconds per testing phase
- Wait time: 100-500ms per wait operation
- Total overhead: 10-20% of task time
Savings
- 50-70% reduction in command count
- 40-50% reduction in testing time
- 20-40 seconds saved per testing phase
Best Practices
- Create composite test functions for common flows
- Batch independent checks with Promise.all() or single eval
- Use simple property checks instead of Promise polling
- Minimize wait times (500ms for transitions, 100ms for checks)
- Check test seam readiness directly (window.TEST?.sceneKey)
- Group related verifications in single calls
- Use Object.keys() for command availability checks
Integration with Other Skills
- phaser-game-testing: Uses these optimization patterns
- browser-testing-efficiency: Complements with additional patterns
- agent-browser: Tool that benefits from optimization
Related Skills
phaser-game-testing - Phaser testing methodology
browser-testing-efficiency - Additional browser testing patterns
agent-browser - Browser automation tool
Remember
- Create composite functions for common flows
- Batch related commands in single eval calls
- Use minimal waits (500ms for transitions)
- Check properties directly (no Promise polling)
- Group verifications together
- Save 40-50% of testing time