71 lines
2.8 KiB
TypeScript
71 lines
2.8 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
// Production domains (override with env vars if needed)
|
|
const BROADCAST_URL = process.env.BROADCAST_URL || 'https://avanzacast-broadcastpanel.bfzqqk.easypanel.host/post_token_to_studio.html?auto=1';
|
|
const STUDIO_ORIGIN = process.env.STUDIO_ORIGIN || 'https://avanzacast-studio.bfzqqk.easypanel.host';
|
|
const TOKEN_SERVER = process.env.TOKEN_SERVER_URL || 'https://avanzacast-servertokens.bfzqqk.easypanel.host';
|
|
|
|
test('broadcast -> token -> studio flow (production domains)', async ({ browser }) => {
|
|
const context = await browser.newContext({ ignoreHTTPSErrors: true });
|
|
const page = await context.newPage();
|
|
|
|
// Navigate to broadcast simulator / page that triggers token creation
|
|
await page.goto(BROADCAST_URL, { waitUntil: 'networkidle' });
|
|
|
|
// Try to trigger flow: either the page auto-runs (auto=1), opens a popup, or requires a click
|
|
// Wait for a new page with studio origin (popup) for up to 12s
|
|
let studioPage = null as (import('@playwright/test').Page | null);
|
|
try {
|
|
const popupPromise = context.waitForEvent('page', { timeout: 12000 });
|
|
|
|
// If there's a visible button, click it (best-effort)
|
|
const openButton = page.locator('text=Open Studio and Send Token, text=Entrar al estudio, text=Open Studio');
|
|
if (await openButton.count() > 0) {
|
|
try { await openButton.first().click({ timeout: 3000 }); } catch (_) { /* ignore */ }
|
|
}
|
|
|
|
// Wait for popup
|
|
studioPage = await popupPromise;
|
|
} catch (e) {
|
|
// popup not opened — maybe the page redirected the same tab
|
|
}
|
|
|
|
// If the broadcast redirected the current page to studio origin
|
|
if (!studioPage && page.url().startsWith(STUDIO_ORIGIN)) {
|
|
studioPage = page;
|
|
}
|
|
|
|
// Fallback: request a session from token server and open the redirectUrl directly
|
|
if (!studioPage) {
|
|
try {
|
|
const resp = await page.request.post(`${TOKEN_SERVER}/api/session`, {
|
|
data: { room: 'studio-demo', username: 'playwright-e2e' },
|
|
timeout: 15000,
|
|
});
|
|
const json = await resp.json();
|
|
const redirectUrl = json?.redirectUrl;
|
|
if (redirectUrl) {
|
|
studioPage = await context.newPage();
|
|
await studioPage.goto(redirectUrl, { waitUntil: 'networkidle' });
|
|
}
|
|
} catch (err) {
|
|
// ignore — we'll assert later
|
|
}
|
|
}
|
|
|
|
expect(studioPage, 'Studio page should be opened (popup or redirect or fallback)')
|
|
.not.toBeNull();
|
|
|
|
// Wait for receiver status element and assert token received
|
|
const status = studioPage!.locator('#status');
|
|
await expect(status).toBeVisible({ timeout: 10000 });
|
|
const txt = await status.innerText();
|
|
expect(txt).toMatch(/Token recibido|Token recibido \(query\)|Token received/i);
|
|
|
|
// Save screenshot for debugging / CI
|
|
await studioPage!.screenshot({ path: '/tmp/e2e_studio_received.png', fullPage: true });
|
|
|
|
await context.close();
|
|
});
|
|
|