Skip to content

Comprehensive Testing System

The comprehensive testing system allows you to run the same set of tests against different environments with just a parameter change.

🎯 Overview

The runComprehensiveTests() method provides a unified testing approach that:

  • Tests any URL: Local development, staging, production, or any environment
  • Detects environment type: Automatically determines if testing a game or documentation site
  • Comprehensive checks: Page load, error detection, functionality testing, and screenshots
  • Flexible execution: Command-line parameters or npm scripts

🚀 Quick Start

Test Local Development

npm run test:comprehensive:local

Test GitHub Pages Game

npm run test:comprehensive:game

Test GitHub Pages Documentation

npm run test:comprehensive:docs

Test All Environments

npm run test:comprehensive:all

Test Custom URL

node advanced-screenshots.js comprehensive https://your-custom-url.com/

📋 Test Coverage

Game Environment Tests

  • ✅ Page load and error detection
  • ✅ Game canvas visibility
  • ✅ Game stats display
  • ✅ Control elements (speed, auto-path, auto-shop)
  • ✅ Game functionality (enemy spawning, controls working)
  • ✅ Screenshot capture

Documentation Environment Tests

  • ✅ Page load and error detection
  • ✅ Navigation visibility
  • ✅ Search functionality
  • ✅ Screenshot capture

Universal Tests

  • ✅ Console error detection
  • ✅ Network error monitoring
  • ✅ Page error handling
  • ✅ Comprehensive error reporting

🔧 Configuration

Environment Detection

The system automatically detects the environment type:

if (baseUrl.includes('/game/') || baseUrl.includes('localhost')) {
  // Run game-specific tests
} else {
  // Run documentation-specific tests
}

Error Handling

  • Console Errors: JavaScript errors and warnings
  • Network Errors: Failed HTTP requests (404s, timeouts)
  • Page Errors: Unhandled exceptions and DOM errors

📊 Test Results

Success Indicators

  • Game Canvas: #gameCanvas visible
  • Game Stats: #stats element present
  • Controls: All game controls functional
  • Navigation: Documentation navigation working
  • Search: Search functionality available

Error Reporting

  • ⚠️ Console Errors: JavaScript errors in browser console
  • Network Errors: Failed resource loading
  • ⚠️ Page Errors: Unhandled exceptions

🛠️ Customization

Adding New Tests

// In runComprehensiveTests method
if (baseUrl.includes('/game/')) {
  // Add custom game tests
  const customTest = await this.page.locator('#customElement').isVisible();
  if (customTest) {
    console.log('✅ Custom test passed');
  }
} else {
  // Add custom documentation tests
  const customDocTest = await this.page.locator('.custom-doc-element').isVisible();
  if (customDocTest) {
    console.log('✅ Custom documentation test passed');
  }
}

Custom Error Thresholds

// Modify error tolerance
const maxErrors = 5;
if (this.consoleErrors.length > maxErrors) {
  console.log(`⚠️ Too many console errors: ${this.consoleErrors.length}`);
}

📁 Output

Screenshots

  • comprehensive-game-test-{timestamp}.png
  • comprehensive-docs-test-{timestamp}.png
  • error-comprehensive-test-{timestamp}.png

Logs

  • Detailed console output with test results
  • Error summaries with counts and types
  • Performance metrics and timing

🔄 Continuous Integration

GitHub Actions Integration

- name: Run Comprehensive Tests
  run: |
    npm run test:comprehensive:game
    npm run test:comprehensive:docs

Pre-deployment Testing

# Test before deployment
npm run test:comprehensive:local
npm run test:comprehensive:game

🎯 Best Practices

  1. Run before deployments: Ensure changes work in all environments
  2. Monitor error patterns: Track recurring issues across environments
  3. Use in CI/CD: Automate testing in deployment pipelines
  4. Customize for your needs: Add environment-specific tests
  5. Review screenshots: Visual verification of functionality

🔍 Troubleshooting

Common Issues

  • Timeout errors: Increase wait times for slow environments
  • Missing elements: Update selectors for different page structures
  • Network errors: Check if resources are available in target environment

Debug Mode

// Enable detailed logging
this.isDebugMode = true;

This unified testing system provides consistent, reliable testing across all environments with minimal configuration changes.

📚 Lessons Learned

Environment-Specific Challenges

Local Development

  • Server Structure: Local dev server serves docs at root (/) and game at /game/
  • Asset Paths: Logo and favicon files may not exist in local environment
  • Expected Errors: 404s for missing assets are normal in local development
  • Solution: Use specific paths (http://localhost:8080/game/) for game testing

GitHub Pages Deployment

  • Asset Organization: Game files are deployed to /game/ subdirectory
  • Favicon Issues: Missing favicon.ico causes console errors but doesn't break functionality
  • API Calls: GitHub API calls for releases may fail (404) but don't affect core functionality
  • Solution: Accept some expected 404s while monitoring for actual issues

Documentation Site

  • Navigation Complexity: MkDocs Material theme has multiple nav elements
  • Selector Specificity: Need specific selectors like nav[data-md-level="0"] instead of generic nav
  • Search Integration: Search functionality is available but may have different implementations
  • Solution: Use precise selectors and test for functionality rather than specific implementations

Error Handling Insights

Expected vs Unexpected Errors

  • Expected: 404s for missing favicon, logo files, GitHub API calls
  • Unexpected: Game canvas not loading, navigation missing, search broken
  • Strategy: Distinguish between cosmetic errors and functional failures

Error Tolerance

  • Console Errors: Some are acceptable (missing assets) while others indicate real problems
  • Network Errors: 404s for optional resources vs critical game files
  • Page Errors: Always indicate problems that need investigation

Selector Strategy

Game Elements

  • Canvas: #gameCanvas - critical for game functionality
  • Stats: #stats and #enemyStats - show game state
  • Controls: #gameSpeed, #autoPath, #autoShop - user interaction
  • Strategy: Test for presence and functionality, not just visibility

Documentation Elements

  • Navigation: nav[data-md-level="0"] - main site navigation
  • Search: [data-md-component="search"] - search functionality
  • Strategy: Focus on core functionality rather than specific styling

Performance Considerations

Wait Times

  • Page Load: 2-3 seconds for initial load
  • Game Start: 3 seconds for game initialization
  • Control Interaction: 500ms-1s for UI responses
  • Strategy: Balance between reliability and speed

Resource Loading

  • Critical Resources: Game JS files, canvas element
  • Optional Resources: Favicons, logos, external APIs
  • Strategy: Fail fast on critical resources, tolerate optional failures

Best Practices Discovered

Environment Detection

// Reliable environment detection
if (baseUrl.includes('/game/') || baseUrl.includes('localhost')) {
  // Game environment
} else {
  // Documentation environment
}

Error Classification

// Classify errors by severity
const criticalErrors = this.networkErrors.filter(e => 
  e.includes('game-ui.js') || e.includes('Game.js')
);
const cosmeticErrors = this.networkErrors.filter(e => 
  e.includes('favicon.ico') || e.includes('logo')
);

Selector Reliability

// Use specific selectors for complex UIs
const nav = await this.page.locator('nav[data-md-level="0"]').isVisible();
const search = await this.page.locator('[data-md-component="search"]').isVisible();

Deployment Integration

Pre-Deployment Testing

# Test local before deploying
npm run test:comprehensive:local

# Verify deployment worked
npm run test:comprehensive:game
npm run test:comprehensive:docs

Continuous Monitoring

  • Run comprehensive tests after each deployment
  • Monitor for new error patterns
  • Update selectors as UI evolves
  • Document environment-specific behaviors

Future Improvements

Enhanced Error Classification

  • Categorize errors by severity and impact
  • Provide actionable error messages
  • Include error context and resolution steps

Environment-Specific Configurations

  • Custom wait times per environment
  • Environment-specific error thresholds
  • Targeted selectors for different deployments

Automated Reporting

  • Generate test reports with pass/fail summaries
  • Track error trends over time
  • Provide deployment health scores

These lessons inform the development of more robust testing systems and help maintain high-quality deployments across all environments.