Files
trading_bot_v3/test-multi-layout.js
mindesbunister 45202cabe7 🚀 Major optimization: Dual-session screenshot service + Docker build speed improvements
 Key Achievements:
- Fixed DIY module screenshot failures - now works 100%
- Optimized Docker builds for i7-4790K (4 cores/8 threads)
- Implemented true parallel dual-session screenshot capture
- Enhanced error diagnostics and navigation timeout handling

🔧 Technical Improvements:
- Enhanced screenshot service with robust parallel session management
- Optimized navigation with 90s timeout and domcontentloaded strategy
- Added comprehensive error handling with browser state capture
- Docker build optimizations: 8-thread npm installs, parallel downloads
- Improved layer caching and reduced build context
- Added fast-build.sh script for optimal CPU utilization

📸 Screenshot Service:
- Parallel AI + DIY module capture working flawlessly
- Enhanced error reporting for debugging navigation issues
- Improved chart loading detection and retry logic
- Better session cleanup and resource management

🐳 Docker Optimizations:
- CPU usage increased from 40% to 80-90% during builds
- Build time reduced from 5-10min to 2-3min
- Better caching and parallel package installation
- Optimized .dockerignore for faster build context

🧪 Testing Infrastructure:
- API-driven test scripts for Docker compatibility
- Enhanced monitoring and diagnostic tools
- Comprehensive error logging and debugging

Ready for AI analysis integration fixes next.
2025-07-13 17:26:49 +02:00

186 lines
6.6 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* Test script for multi-layout screenshot functionality
* Tests AI and DIY layout switching and screenshot capture
*/
const { enhancedScreenshotService } = require('./lib/enhanced-screenshot.ts')
async function testMultiLayoutScreenshots() {
console.log('🧪 Testing Multi-Layout Screenshot Functionality\n')
try {
// Test configuration with multiple layouts
const testConfig = {
symbol: 'SOLUSD',
timeframe: '240', // 4-hour chart
layouts: ['ai', 'diy'] // Test both AI and DIY layouts
}
console.log('📋 Test Configuration:')
console.log(` Symbol: ${testConfig.symbol}`)
console.log(` Timeframe: ${testConfig.timeframe} minutes (4h)`)
console.log(` Layouts: ${testConfig.layouts.join(', ')}`)
console.log('')
console.log('🚀 Starting multi-layout screenshot capture...')
// Capture screenshots with multiple layouts
const screenshots = await enhancedScreenshotService.captureWithLogin(testConfig)
console.log('\n✅ Multi-layout screenshot test completed!')
console.log(`📸 Total screenshots captured: ${screenshots.length}`)
if (screenshots.length > 0) {
console.log('\n📂 Screenshots captured:')
screenshots.forEach((screenshot, index) => {
console.log(` ${index + 1}. ${screenshot}`)
})
// Expected screenshots:
// 1. Default layout screenshot
// 2. AI layout screenshot
// 3. DIY layout screenshot
const expectedCount = 1 + testConfig.layouts.length // default + each layout
if (screenshots.length >= expectedCount) {
console.log(`\n🎉 SUCCESS: Expected ${expectedCount} screenshots, got ${screenshots.length}`)
// Check if screenshots have the correct naming
const hasDefaultScreenshot = screenshots.some(s => s.includes('_default.png'))
const hasAIScreenshot = screenshots.some(s => s.includes('_ai_'))
const hasDIYScreenshot = screenshots.some(s => s.includes('_diy_'))
console.log('\n🔍 Screenshot Analysis:')
console.log(` Default layout: ${hasDefaultScreenshot ? '✅' : '❌'}`)
console.log(` AI layout: ${hasAIScreenshot ? '✅' : '❌'}`)
console.log(` DIY layout: ${hasDIYScreenshot ? '✅' : '❌'}`)
if (hasDefaultScreenshot && hasAIScreenshot && hasDIYScreenshot) {
console.log('\n🏆 PERFECT: All expected layouts were captured!')
} else {
console.log('\n⚠ Some layouts may not have been captured correctly')
}
} else {
console.log(`\n⚠️ Expected ${expectedCount} screenshots, but got ${screenshots.length}`)
console.log(' This might indicate layout switching issues')
}
} else {
console.log('\n❌ No screenshots were captured')
}
} catch (error) {
console.error('\n❌ Multi-layout screenshot test failed:')
console.error(error.message)
if (error.message.includes('CAPTCHA') || error.message.includes('manual intervention')) {
console.log('\n💡 CAPTCHA detected - this is expected in Docker environment')
console.log(' The manual CAPTCHA handling workflow should have been triggered')
console.log(' Check if the browser switched to non-headless mode for CAPTCHA solving')
}
if (error.message.includes('layout')) {
console.log('\n🔧 Layout switching issues detected:')
console.log(' - Check if TradingView layout selectors are correct')
console.log(' - Verify AI and DIY modules are available on the chart')
console.log(' - Layout detection logic may need refinement')
}
}
}
async function testLayoutSwitchingOnly() {
console.log('\n🔄 Testing Layout Switching Logic Only\n')
try {
// Get the TradingView automation instance
const { tradingViewAutomation } = require('./lib/tradingview-automation.ts')
console.log('🔧 Initializing browser...')
await tradingViewAutomation.init()
console.log('🔐 Checking login status...')
const isLoggedIn = await tradingViewAutomation.isLoggedIn()
if (!isLoggedIn) {
console.log('⚠️ Not logged in - attempting smart login...')
const loginSuccess = await tradingViewAutomation.smartLogin()
if (!loginSuccess) {
throw new Error('Login required for layout switching test')
}
}
console.log('🗺️ Navigating to chart...')
await tradingViewAutomation.navigateToChart({
symbol: 'SOLUSD',
timeframe: '240',
waitForChart: true
})
console.log('⏳ Waiting for chart data...')
await tradingViewAutomation.waitForChartData()
// Test layout switching
const layoutsToTest = ['ai', 'diy']
for (const layout of layoutsToTest) {
console.log(`\n🎛️ Testing ${layout.toUpperCase()} layout switch...`)
const switchSuccess = await tradingViewAutomation.switchLayout(layout)
console.log(` Switch attempt: ${switchSuccess ? '✅' : '❌'}`)
if (switchSuccess) {
console.log(` ⏳ Waiting for ${layout} layout to load...`)
const loadSuccess = await tradingViewAutomation.waitForLayoutLoad(layout)
console.log(` Load detection: ${loadSuccess ? '✅' : '❌'}`)
// Take a test screenshot
const testScreenshot = `test_${layout}_layout_${Date.now()}.png`
console.log(` 📸 Taking test screenshot: ${testScreenshot}`)
await tradingViewAutomation.takeScreenshot(testScreenshot)
}
}
console.log('\n✅ Layout switching test completed')
} catch (error) {
console.error('\n❌ Layout switching test failed:')
console.error(error.message)
}
}
async function main() {
console.log('🔬 Multi-Layout Screenshot Test Suite')
console.log('=====================================\n')
// Test 1: Full multi-layout screenshot capture
await testMultiLayoutScreenshots()
// Test 2: Layout switching logic only
await testLayoutSwitchingOnly()
console.log('\n🏁 Test suite completed')
console.log('Check the screenshots directory for captured images')
console.log('Review browser logs for any layout switching issues')
}
// Handle cleanup on exit
process.on('SIGINT', async () => {
console.log('\n🛑 Test interrupted - cleaning up...')
try {
const { tradingViewAutomation } = require('./lib/tradingview-automation.ts')
await tradingViewAutomation.close()
} catch (error) {
// Ignore cleanup errors
}
process.exit(0)
})
// Run the tests
main().catch(error => {
console.error('Test suite failed:', error)
process.exit(1)
})