run-customer.mjs 1.2 KB

123456789101112131415161718
  1. import { readFile } from 'node:fs/promises';
  2. import { chromium } from 'playwright';
  3. import { checkCustomer } from './customer-functional.mjs';
  4. const accounts = JSON.parse(await readFile(new URL('../../.work/frontend-accounts.json', import.meta.url), 'utf8'));
  5. const browser = await chromium.launch({ executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE || 'C:/Users/Administrator/AppData/Local/ms-playwright/chromium-1228/chrome-win64/chrome.exe', headless: true });
  6. const page = await browser.newPage({ viewport: { width: 390, height: 844 } });
  7. page.setDefaultTimeout(15000);
  8. page.on('pageerror', error => console.error('浏览器错误:', error.message));
  9. page.on('response', async response => { if (response.status() >= 400) console.error('HTTP', response.status(), new URL(response.url()).pathname, await response.text()); });
  10. try {
  11. const results = await checkCustomer(page, process.env.FRONTEND_URL || 'http://127.0.0.1:18762', accounts);
  12. console.log(JSON.stringify({ passed: results }, null, 2));
  13. } catch (error) {
  14. console.error('当前页面:', page.url());
  15. console.error(await page.locator('body').innerText());
  16. throw error;
  17. } finally { await browser.close(); }