-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclick_test.js
More file actions
94 lines (74 loc) · 3.12 KB
/
click_test.js
File metadata and controls
94 lines (74 loc) · 3.12 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
89
90
91
92
93
94
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
async function clickTest() {
console.log('\n=== CLICK TEST ===');
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ ignoreHTTPSErrors: true });
const page = await context.newPage();
const pageUrl = process.env.GAME_URL || 'http://localhost:8888/STARSECTOR_V6J_FINAL_WORKING.html';
const outputDir = path.join(__dirname, 'test_output');
fs.mkdirSync(outputDir, { recursive: true });
let allMessages = [];
let allErrors = [];
page.on('console', msg => {
const text = msg.text();
allMessages.push({ type: msg.type(), text });
console.log(`[${msg.type()}] ${text}`);
});
page.on('pageerror', err => {
allErrors.push(err.message);
console.error('[ERROR]', err.message);
});
try {
console.log('\n1. Loading page...');
await page.goto(pageUrl, { waitUntil: 'domcontentloaded', timeout: 15000 });
console.log(' ✅ Page loaded');
await page.waitForTimeout(1000);
console.log('\n2. Clicking INITIALIZE...');
await page.click('#initButton', { timeout: 5000 });
console.log(' ✅ Clicked');
console.log('\n3. Waiting 10 seconds for initialization...');
await page.waitForTimeout(10000);
console.log(' ✅ Waited');
console.log('\n4. Checking log output...');
const logText = await page.$eval('#log', el => el.innerText).catch(() => 'No logs');
console.log('\n--- LOGS AFTER INITIALIZE ---');
console.log(logText);
console.log('--- END LOGS ---\n');
console.log('\n5. Checking if launch button enabled...');
const launchEnabled = await page.$eval('#launchButton', el => !el.disabled).catch(() => false);
console.log(` Launch button enabled: ${launchEnabled}`);
if (launchEnabled) {
console.log('\n6. Clicking LAUNCH...');
await page.click('#launchButton', { timeout: 5000 });
console.log(' ✅ Clicked');
console.log('\n7. Waiting 15 seconds for launch...');
await page.waitForTimeout(15000);
console.log(' ✅ Waited');
console.log('\n8. Getting final logs...');
const finalLogText = await page.$eval('#log', el => el.innerText).catch(() => 'No logs');
console.log('\n--- FINAL LOGS ---');
console.log(finalLogText);
console.log('--- END FINAL LOGS ---\n');
} else {
console.log('\n Launch button not enabled, cannot launch');
}
const screenshotPath = path.join(outputDir, 'click_test_screenshot.png');
await page.screenshot({ path: screenshotPath, fullPage: true });
console.log(`\n 📸 Screenshot saved to ${screenshotPath}`);
} catch (e) {
console.error('\n ❌ ERROR:', e.message);
allErrors.push(e.message);
}
await browser.close();
console.log('\n=== TEST SUMMARY ===');
console.log(`Total messages: ${allMessages.length}`);
console.log(`Total errors: ${allErrors.length}`);
if (allErrors.length > 0) {
console.log('\nErrors:');
allErrors.forEach((err, i) => console.log(`${i+1}. ${err}`));
}
console.log('\n=== DONE ===\n');
}
clickTest().catch(console.error);