-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e-test.cjs
More file actions
150 lines (130 loc) · 6.12 KB
/
Copy pathe2e-test.cjs
File metadata and controls
150 lines (130 loc) · 6.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const { chromium } = require('playwright');
async function screenshot(page, name) {
await page.screenshot({ path: `test-results/${name}.png`, fullPage: true });
console.log(` [OK] test-results/${name}.png`);
}
async function main() {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1706, height: 1200 } });
const page = await context.newPage();
console.log('============================================================');
console.log('TIMORUP COMPREHENSIVE E2E TEST');
console.log('============================================================');
// ========== PUBLIC PAGES ==========
console.log('\n## PUBLIC PAGES ##\n');
const publicPages = [
{ url: '/', name: 'home' },
{ url: '/businesses', name: 'businesses-listing' },
{ url: '/business/casa-maria-restaurant', name: 'business-detail-casa' },
{ url: '/business/dili-electronics', name: 'business-detail-dili' },
{ url: '/business/hotel-timor', name: 'business-detail-hotel' },
{ url: '/non-profits', name: 'non-profits' },
{ url: '/public-sectors', name: 'public-sectors' },
{ url: '/listings', name: 'classified-ads' },
];
for (const p of publicPages) {
const resp = await page.goto(`http://127.0.0.1:8787${p.url}`);
await page.waitForLoadState('domcontentloaded');
const status = resp?.status() || 0;
const title = await page.title();
console.log(` ${p.url}: ${status} "${title}"`);
await screenshot(page, p.name);
}
// ========== LOGIN PAGE ==========
console.log('\n## LOGIN PAGE ##\n');
await page.goto('http://127.0.0.1:8787/login');
await page.waitForLoadState('networkidle');
console.log(' Login page loaded:', await page.title());
await screenshot(page, 'login-page');
// ========== USER LOGIN ==========
console.log('\n## USER LOGIN (user1@timorup.com) ##\n');
await page.waitForTimeout(2000);
await page.locator('input[name="email"]').fill('user1@timorup.com');
await page.locator('input[name="password"]').fill('user12345');
// Use force click to bypass pointer-event interception from parent form
await page.locator('#submit-btn').click({ force: true });
await page.waitForTimeout(8000);
const userUrl = page.url();
console.log(' After login URL:', userUrl);
await screenshot(page, 'user-after-login');
if (userUrl.includes('account') || userUrl.includes('dashboard')) {
console.log(' [OK] User logged in successfully');
for (const p of ['/account', '/account/profile']) {
const r = await page.goto(`http://127.0.0.1:8787${p}`);
await page.waitForLoadState('domcontentloaded');
console.log(` ${p}: ${r?.status() || 0} "${await page.title()}"`);
await screenshot(page, `user${p.replace(/\//g, '-')}`);
}
} else {
console.log(' [WARN] Login did not redirect, checking for errors...');
const formMsg = await page.locator('#form-message').textContent().catch(() => '');
console.log(' Form message:', formMsg || '(empty)');
const pageText = await page.evaluate(() => document.body.innerText.slice(0, 500));
console.log(' Page text:', pageText);
}
// ========== ADMIN LOGIN ==========
console.log('\n## ADMIN LOGIN (admin@timorup.com) ##\n');
await context.clearCookies();
await page.goto('http://127.0.0.1:8787/login');
await page.waitForTimeout(2000);
await page.locator('input[name="email"]').fill('admin@timorup.com');
await page.locator('input[name="password"]').fill('admin12345');
await page.locator('#submit-btn').click({ force: true });
await page.waitForTimeout(8000);
const adminUrl = page.url();
console.log(' After admin login URL:', adminUrl);
await screenshot(page, 'admin-after-login');
if (adminUrl.includes('admin') || adminUrl.includes('account')) {
console.log(' [OK] Admin logged in successfully');
const adminPages = [
{ url: '/admin', name: 'admin-dashboard' },
{ url: '/admin/products', name: 'admin-products' },
{ url: '/admin/orders', name: 'admin-orders' },
{ url: '/admin/ad-banners', name: 'admin-ad-banners' },
{ url: '/admin/service-packages', name: 'admin-service-packages' },
{ url: '/admin/users', name: 'admin-users' },
{ url: '/admin/categories', name: 'admin-categories' },
{ url: '/admin/settings', name: 'admin-settings' },
];
for (const p of adminPages) {
const r = await page.goto(`http://127.0.0.1:8787${p.url}`);
await page.waitForLoadState('domcontentloaded');
const h1 = await page.locator('h1, h2').first().textContent().catch(() => '(no heading)');
console.log(` ${p.url}: ${r?.status() || 0} "${h1.trim()}"`);
await screenshot(page, p.name);
}
} else {
console.log(' [WARN] Admin login did not redirect');
const formMsg = await page.locator('#form-message').textContent().catch(() => '');
console.log(' Form message:', formMsg || '(empty)');
}
// ========== REGISTER PAGE ==========
console.log('\n## REGISTER PAGE ##\n');
await context.clearCookies();
await page.goto('http://127.0.0.1:8787/register');
await page.waitForLoadState('networkidle');
console.log(' Register page:', await page.title());
await screenshot(page, 'register-page');
// ========== SEARCH FUNCTIONALITY ==========
console.log('\n## SEARCH FUNCTIONALITY ##\n');
await page.goto('http://127.0.0.1:8787/businesses');
await page.waitForLoadState('networkidle');
const searchBox = page.locator('input[placeholder*="Search"], input[type="search"]').first();
if (await searchBox.isVisible()) {
await searchBox.fill('electronics');
await searchBox.press('Enter');
await page.waitForLoadState('networkidle');
console.log(' Search "electronics" results:', await page.title());
await screenshot(page, 'search-results');
} else {
console.log(' [SKIP] No search box found');
}
await browser.close();
console.log('\n============================================================');
console.log('TEST COMPLETE - All screenshots in test-results/');
console.log('============================================================');
}
main().catch(e => {
console.error('Test error:', e.message);
process.exit(1);
});