164 lines
4.7 KiB
JavaScript
164 lines
4.7 KiB
JavaScript
import PLCStreamerBrowserAutomation from './browser-automation.js';
|
|
|
|
/**
|
|
* Ejemplo de uso de la automatización de Playwright para PLC Streamer
|
|
*/
|
|
async function runExample() {
|
|
const automation = new PLCStreamerBrowserAutomation();
|
|
|
|
try {
|
|
console.log('🚀 Iniciando automatización de ejemplo...');
|
|
|
|
// Inicializar navegador
|
|
await automation.initBrowser('chromium', {
|
|
headless: false,
|
|
slowMo: 500 // Ralentizar para ver las acciones
|
|
});
|
|
|
|
console.log('✅ Navegador inicializado');
|
|
|
|
// Verificar que el backend esté funcionando
|
|
const backendStatus = await automation.checkBackendStatus();
|
|
console.log(`🔧 Estado del backend: ${backendStatus ? 'Online' : 'Offline'}`);
|
|
|
|
if (!backendStatus) {
|
|
console.log('⚠️ Backend no disponible. Asegúrate de que esté ejecutándose en puerto 5000');
|
|
return;
|
|
}
|
|
|
|
// Navegar a la aplicación
|
|
console.log('🌐 Navegando a la aplicación...');
|
|
await automation.navigateToApp();
|
|
|
|
// Monitorear estado PLC
|
|
console.log('🔌 Verificando estado de conexión PLC...');
|
|
const plcStatus = await automation.monitorPLCConnection();
|
|
console.log(`PLC Status: ${plcStatus}`);
|
|
|
|
// Test de configuración
|
|
console.log('⚙️ Ejecutando test de configuración...');
|
|
await automation.testConfigurationFlow();
|
|
|
|
// Test de streaming
|
|
console.log('📊 Ejecutando test de streaming...');
|
|
await automation.testStreamingFlow();
|
|
|
|
// Capturar screenshots
|
|
console.log('📸 Capturando screenshots...');
|
|
await automation.captureScreenshots();
|
|
|
|
// Monitorear performance
|
|
console.log('⚡ Analizando performance...');
|
|
await automation.monitorPerformance();
|
|
|
|
// Generar reporte
|
|
console.log('📋 Generando reporte...');
|
|
const report = await automation.generateReport();
|
|
|
|
console.log('🎉 Automatización completada exitosamente!');
|
|
console.log('📊 Reporte:', report);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error en la automatización:', error);
|
|
} finally {
|
|
// Cleanup
|
|
await automation.cleanup();
|
|
console.log('🧹 Recursos liberados');
|
|
}
|
|
}
|
|
|
|
// Función para testing específico
|
|
async function testSpecificFeature(feature) {
|
|
const automation = new PLCStreamerBrowserAutomation();
|
|
|
|
try {
|
|
await automation.initBrowser('chromium', { headless: false });
|
|
await automation.navigateToApp();
|
|
|
|
switch (feature) {
|
|
case 'configuration':
|
|
await automation.testConfigurationFlow();
|
|
break;
|
|
case 'streaming':
|
|
await automation.testStreamingFlow();
|
|
break;
|
|
case 'screenshots':
|
|
await automation.captureScreenshots();
|
|
break;
|
|
case 'performance':
|
|
await automation.monitorPerformance();
|
|
break;
|
|
default:
|
|
console.log('Características disponibles: configuration, streaming, screenshots, performance');
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
} finally {
|
|
await automation.cleanup();
|
|
}
|
|
}
|
|
|
|
// Función para monitoreo continuo
|
|
async function continuousMonitoring(durationMinutes = 5) {
|
|
const automation = new PLCStreamerBrowserAutomation();
|
|
|
|
try {
|
|
await automation.initBrowser('chromium', { headless: true });
|
|
await automation.navigateToApp();
|
|
|
|
const endTime = Date.now() + (durationMinutes * 60 * 1000);
|
|
|
|
console.log(`🔄 Iniciando monitoreo continuo por ${durationMinutes} minutos...`);
|
|
|
|
while (Date.now() < endTime) {
|
|
const status = await automation.monitorPLCConnection();
|
|
const timestamp = new Date().toISOString();
|
|
|
|
console.log(`[${timestamp}] PLC Status: ${status}`);
|
|
|
|
// Esperar 30 segundos antes del siguiente check
|
|
await new Promise(resolve => setTimeout(resolve, 30000));
|
|
}
|
|
|
|
console.log('✅ Monitoreo continuo completado');
|
|
|
|
} catch (error) {
|
|
console.error('Error en monitoreo:', error);
|
|
} finally {
|
|
await automation.cleanup();
|
|
}
|
|
}
|
|
|
|
// Detectar argumentos de línea de comandos
|
|
const args = process.argv.slice(2);
|
|
|
|
if (args.length === 0) {
|
|
// Ejecutar ejemplo completo
|
|
runExample();
|
|
} else if (args[0] === 'test' && args[1]) {
|
|
// Ejecutar test específico
|
|
testSpecificFeature(args[1]);
|
|
} else if (args[0] === 'monitor') {
|
|
// Ejecutar monitoreo continuo
|
|
const duration = args[1] ? parseInt(args[1]) : 5;
|
|
continuousMonitoring(duration);
|
|
} else {
|
|
console.log(`
|
|
Uso:
|
|
node example.js # Ejecutar ejemplo completo
|
|
node example.js test <feature> # Ejecutar test específico
|
|
node example.js monitor [minutes] # Monitoreo continuo
|
|
|
|
Características disponibles:
|
|
- configuration
|
|
- streaming
|
|
- screenshots
|
|
- performance
|
|
|
|
Ejemplos:
|
|
node example.js test configuration
|
|
node example.js monitor 10
|
|
`);
|
|
}
|