An automated web game player designed to play the "Trolley Problem" style game on trollilopolis.com once per day. This project serves two main purposes:
- Keep the game active: Prevents the game's backend and database from shutting down due to inactivity
- Quality Assurance foundation: Provides a framework for automated testing and monitoring of web games
- 🤖 Automated gameplay: Simulates user interactions with the trolley problem game
- 📅 Scheduled execution: Runs daily at a configurable time (default 6:00 AM)
- 📊 Comprehensive logging: Captures text logs, screenshots, network requests, and console output
- 🔄 Error handling: Built-in retry mechanisms and graceful error recovery
- ⚙️ Configurable: Easy customization of game settings, schedules, and behavior
- 🎯 Manual triggers: Run games on-demand for testing and debugging
- 📸 Visual documentation: Screenshots of each game step for verification
-
Clone and setup:
git clone <repository-url> cd jenkins npm install
-
Configure the game (optional): Edit
config/config.json
to customize settings:{ "game": { "url": "https://trollilopolis.com", "maxScenarios": 10 }, "schedule": { "dailyRunTime": "6:00", "enabled": true }, "browser": { "headless": false } }
-
Run manually first (recommended):
npm run play
-
Start the scheduler:
npm start
# Run game manually (immediate execution)
npm run play
# Start daily scheduler
npm start
# Check current status and configuration
node index.js --status
# Get help
node index.js --help
jenkins/
├── config/
│ └── config.json # Configuration settings
├── src/
│ ├── gamePlayer.js # Core game automation logic
│ ├── logger.js # Logging and screenshot utilities
│ ├── scheduler.js # Cron scheduling system
│ └── errorHandler.js # Error handling and retry logic
├── logs/ # Text logs and network/console data
├── screenshots/ # Visual documentation of game runs
├── index.js # Main application entry point
├── package.json
└── README.md
The config/config.json
file contains all customizable settings:
url
: The game URL (default: "https://trollilopolis.com")maxScenarios
: Maximum number of scenarios to play (default: 10)waitTime
: Delay between actions in milliseconds (default: 2000)
headless
: Run browser in background (false = visible, true = hidden)timeout
: Page load timeout in millisecondsviewport
: Browser window dimensions
dailyRunTime
: Daily execution time in "HH:MM" formatenabled
: Enable/disable scheduled runstimezone
: Timezone for scheduling
screenshotQuality
: PNG quality for screenshots (0-100)captureNetwork
: Record network requestscaptureConsole
: Record browser console outputretainLogs
: Days to keep old log files
strategy
: How to make choices ("random", "pattern", "left", "right")pattern
: Sequence of choices when using pattern strategy
maxRetries
: Number of retry attempts for failed actionsretryDelay
: Wait time between retries (milliseconds)continueOnMinorErrors
: Whether to continue after recoverable errors
The application includes a built-in scheduler using node-cron:
npm start # Runs continuously with daily scheduling
For system-level scheduling, add to crontab:
# Edit crontab
crontab -e
# Add daily 6 AM execution
0 6 * * * cd /path/to/jenkins && npm run play >> /path/to/jenkins/logs/cron.log 2>&1
Create a Jenkins job with:
- Build Triggers: "Build periodically" with cron expression
0 6 * * *
- Build Steps: Execute shell command
npm run play
Each run generates several types of output:
- Main log:
YYYY-MM-DDTHH-MM-SS.log
- Chronological action log - Network log:
*-network.json
- HTTP requests and responses - Console log:
*-console.json
- Browser console output
01-game-loaded.png
- Initial page load02-game-started.png
- After clicking start03-scenario-N.png
- Each scenario presentation04-choice-N.png
- After each choice is made05-game-end.png
- Final game state
Real-time progress updates displayed during execution.
-
Game won't start:
- Check if the game URL is accessible
- Verify start button selectors in config
- Run with
headless: false
to see what's happening
-
Browser fails to launch:
- Ensure Chrome/Chromium is installed
- On Linux servers, you may need:
apt-get install chromium-browser
- Check system resources (memory/CPU)
-
Elements not found:
- Game layout may have changed
- Update selectors in
config.json
- Check screenshots to see current page state
-
Scheduling not working:
- Verify
schedule.enabled: true
in config - Check system timezone matches config
- For system cron, ensure path is absolute
- Verify
Run with visible browser to debug issues:
{
"browser": {
"headless": false
}
}
Check the most recent log file for detailed execution information:
# View latest log
ls -la logs/
tail -f logs/2024-01-15T06-00-00.log
# View screenshots
open screenshots/2024-01-15T06-00-00/
- Create a new config section for the game
- Extend
GamePlayer
class or create a new player class - Update selectors and interaction logic
- Test thoroughly with manual runs
Modify the determineChoice()
method in GamePlayer
:
determineChoice() {
// Custom logic here
// Return 'left' or 'right'
}
Extend the Logger
class to add new output formats or destinations.
- No sensitive data: The system doesn't handle passwords or sensitive information
- Local storage: All logs are stored locally by default
- Rate limiting: Built-in delays prevent overwhelming the game server
- Graceful degradation: Designed to fail safely without breaking the game
- Resource usage: Browser automation uses CPU and memory
- Network usage: Minimal - only loads the game pages
- Storage: Screenshots and logs accumulate over time (auto-cleanup available)
- Headless mode: Use
headless: true
for lower resource usage on servers
For issues, questions, or contributions:
- Check the logs for error details
- Review this documentation
- Test with manual execution first
- Create an issue with log files and configuration
🔗 Repository: https://github.com/callumreid/jenkins-automated-game-player
- 🎮 Daily Game Player: Main production runs at 6:00 AM UTC + test at 3:45 PM UTC
- 🧪 Test Automation: Verification runs at 3:45 PM & 11:11 AM UTC with 2 scenarios
- 🤖 Test Suite: Comprehensive testing on pushes and pull requests
- 📊 Artifacts: Logs and screenshots saved (30 days for daily, 14 days for tests)
- 🚀 Manual Dispatch: Trigger runs on-demand with custom scenario counts
- ✅ Automated daily gameplay via GitHub Actions
- ✅ Comprehensive CI/CD testing pipeline
- ✅ Artifact management with automatic cleanup
- ✅ Workflow summaries with game statistics
- ✅ Manual triggers for testing and debugging
ISC License - See package.json for details.
Jenkins Automated Game Player - Keep your games alive, catch issues early