Files
thankcard-system/capture-screenshots.js
T

59 lines
1.9 KiB
JavaScript

import puppeteer from 'puppeteer';
import fs from 'fs';
import path from 'path';
(async () => {
const dir = './docs/notification-review';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir, { recursive: true });
}
console.log('Launching browser...');
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
console.log('Navigating to showcase...');
await page.goto('http://localhost:8000/notification-showcase', { waitUntil: 'networkidle2' });
const cases = [
{ id: 1, name: 'login_failed' },
{ id: 2, name: 'access_denied' },
{ id: 3, name: 'first_login' },
{ id: 4, name: 'delete_user_confirmation' },
{ id: 5, name: 'create_user_success' },
{ id: 6, name: 'email_already_exists' },
{ id: 7, name: 'employee_id_already_exists' },
{ id: 8, name: 'no_data_found' },
{ id: 9, name: 'not_enough_thankcards' },
{ id: 10, name: 'max_5_thankcards_per_month' },
{ id: 11, name: 'send_thankcards_confirmation' },
{ id: 12, name: 'send_thankcards_success' },
{ id: 13, name: 'password_confirmation_mismatch' },
{ id: 14, name: 'change_password_success' },
{ id: 15, name: 'generic_system_error' }
];
for (const c of cases) {
console.log(`Triggering Case ${c.id}: ${c.name}...`);
// Click the button
await page.click(`#case-btn-${c.id}`);
// Wait for animation
await new Promise(resolve => setTimeout(resolve, 800));
// Save screenshot
const filename = `case_${String(c.id).padStart(2, '0')}_${c.name}.png`;
const filepath = path.join(dir, filename);
await page.screenshot({ path: filepath });
console.log(`Saved screenshot to ${filepath}`);
}
await browser.close();
console.log('Finished capturing all 15 screenshots!');
})();