-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestJoin.js
More file actions
executable file
·88 lines (76 loc) · 2.54 KB
/
Copy pathtestJoin.js
File metadata and controls
executable file
·88 lines (76 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
require('dotenv').config({ quiet: true });
const { chromium } = require('playwright');
const CHROMIUM_FLAGS = [
'--use-fake-ui-for-media-stream',
'--use-fake-device-for-media-stream',
'--mute-audio',
];
const SEL = {
nameField: 'input[placeholder="Guest"]',
joinButton: '.media-settings button.join-call',
};
function parseBool(name, fallback) {
const raw = process.env[name];
if (raw === undefined) return fallback;
switch (raw.toLowerCase()) {
case '1': case 'true': case 'yes': case 'on': return true;
case '0': case 'false': case 'no': case 'off': return false;
default:
console.error(`Env ${name}: expected boolean, got "${raw}"`);
process.exit(2);
}
}
function parsePositiveInt(name, fallback) {
const raw = process.env[name];
if (raw === undefined) return fallback;
const n = Number(raw);
if (!Number.isInteger(n) || n < 0) {
console.error(`Env ${name}: expected non-negative integer, got "${raw}"`);
process.exit(2);
}
return n;
}
function readConfig() {
const url = process.env.CALL_URL;
if (!url) {
console.error('CALL_URL is required (e.g. https://nc.example.com/call/abc123)');
process.exit(2);
}
return {
url,
guestName: process.env.USER_NAME || 'Playwright Test User',
holdSec: parsePositiveInt('CALL_DURATION_SECONDS', 60),
headless: parseBool('HEADLESS', true),
};
}
async function runSmokeTest(cfg) {
const browser = await chromium.launch({ headless: cfg.headless, args: CHROMIUM_FLAGS });
try {
const context = await browser.newContext({
permissions: ['microphone', 'camera'],
locale: 'en-US',
extraHTTPHeaders: { 'Accept-Language': 'en-US,en;q=0.9' },
});
const page = await context.newPage();
console.log(`Opening ${cfg.url}`);
await page.goto(cfg.url, { waitUntil: 'domcontentloaded' });
const nameField = page.locator(SEL.nameField);
await nameField.waitFor({ state: 'visible', timeout: 30_000 });
console.log(`Filling guest name "${cfg.guestName}"`);
await nameField.fill(cfg.guestName);
const joinBtn = page.locator(SEL.joinButton);
await joinBtn.waitFor({ state: 'visible', timeout: 30_000 });
console.log('Clicking Join call');
await joinBtn.click();
console.log(`Joined. Holding ${cfg.holdSec}s before leaving.`);
await page.waitForTimeout(cfg.holdSec * 1000);
console.log('Done.');
} finally {
await browser.close().catch(() => {});
}
}
runSmokeTest(readConfig()).catch(err => {
console.error('Smoke test failed:', err.message);
process.exit(1);
});