AvanzaCast/e2e/streamyard-flow-remote.js
Cesar Mendivil 8b458a3ddf feat: add initial LiveKit Meet integration with utility scripts, configs, and core components
- Add Next.js app structure with base configs, linting, and formatting
- Implement LiveKit Meet page, types, and utility functions
- Add Docker, Compose, and deployment scripts for backend and token server
- Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers
- Include CSS modules and global styles for UI
- Add postMessage and studio integration utilities
- Update package.json with dependencies and scripts for development and testing
2025-11-20 12:50:38 -07:00

100 lines
3.6 KiB
JavaScript

// e2e/streamyard-flow-remote.js
// Connect to a remote Playwright server via wsEndpoint and run the StreamYard flow
// Usage:
// PW_WS=ws://192.168.1.20:3003 node e2e/streamyard-flow-remote.js
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
(async () => {
const outDir = path.resolve(__dirname);
const results = { startedAt: new Date().toISOString(), console: [], navigations: [] };
const ws = process.env.PW_WS || 'ws://192.168.1.20:3003';
console.log('Connecting to Playwright WS at', ws);
let browser;
try {
browser = await chromium.connect({ wsEndpoint: ws, timeout: 30000 });
} catch (err) {
console.error('Failed to connect to Playwright server:', err && err.message ? err.message : err);
process.exit(2);
}
const context = await browser.newContext();
const page = await context.newPage();
page.on('console', msg => {
try { results.console.push({ type: msg.type(), text: msg.text() }); } catch(e){}
});
page.on('pageerror', err => { results.console.push({ type: 'pageerror', text: String(err && err.stack ? err.stack : err) }); });
try {
const startUrl = 'https://streamyard.com/';
console.log('goto', startUrl);
await page.goto(startUrl, { waitUntil: 'networkidle', timeout: 30000 });
await page.waitForTimeout(1500);
const loc = page.locator('text=Entrar al estudio');
const count = await loc.count();
console.log('found', count, 'elements');
results.found = count;
for (let i = 0; i < count; i++) {
const el = loc.nth(i);
const beforeHref = await el.getAttribute('href');
const navRec = { index: i, beforeHref, attempts: [] };
let clicked = false;
for (let attempt = 1; attempt <= 3; attempt++) {
const att = { attempt, timestamp: new Date().toISOString() };
try {
const navPromise = page.waitForNavigation({ waitUntil: 'networkidle', timeout: 10000 }).catch(() => null);
await el.click({ force: true, timeout: 5000 });
const nav = await navPromise;
att.afterUrl = page.url();
att.navigated = !!nav;
att.ok = true;
navRec.attempts.push(att);
clicked = true;
if (nav) {
await page.waitForTimeout(800);
await page.goto(startUrl, { waitUntil: 'networkidle', timeout: 30000 });
await page.waitForTimeout(800);
}
break;
} catch (err) {
att.ok = false;
att.error = String(err.message || err);
navRec.attempts.push(att);
await page.waitForTimeout(700);
}
}
navRec.success = clicked;
results.navigations.push(navRec);
}
const screenshotPath = path.join(outDir, 'streamyard_flow_remote.png');
await page.screenshot({ path: screenshotPath, fullPage: true });
results.screenshot = screenshotPath;
results.endedAt = new Date().toISOString();
const jsonOut = path.join(outDir, 'streamyard-flow-remote-result.json');
fs.writeFileSync(jsonOut, JSON.stringify(results, null, 2));
console.log('Wrote results to', jsonOut);
await context.close();
try { await browser.close(); } catch(e) { try { await browser.disconnect(); } catch(e){} }
process.exit(0);
} catch (err) {
console.error('Error during flow', err);
results.error = String(err && err.stack ? err.stack : err);
results.endedAt = new Date().toISOString();
fs.writeFileSync(path.join(outDir, 'streamyard-flow-remote-result.json'), JSON.stringify(results, null, 2));
try { await context.close(); } catch(e){}
try { await browser.close(); } catch(e){}
process.exit(1);
}
})();