import { chromium } from '@playwright/test'; import * as fs from 'fs'; import * as path from 'path'; (async () => { const browser = await chromium.launch({ headless: true }); const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }); console.log('正在访问首页...'); await page.goto('http://localhost:3000'); await page.waitForLoadState('networkidle'); await page.waitForTimeout(2000); const screenshotDir = '/tmp/screenshots'; if (!fs.existsSync(screenshotDir)) { fs.mkdirSync(screenshotDir, { recursive: true }); } // 首页 Hero await page.screenshot({ path: path.join(screenshotDir, '01-home-hero.png') }); console.log('✓ 首页 Hero 截图已保存'); // Stats 区域 await page.evaluate(() => window.scrollTo(0, 1400)); await page.waitForTimeout(1000); await page.screenshot({ path: path.join(screenshotDir, '02-stats-section.png') }); console.log('✓ Stats 区域截图已保存'); // 服务区域 await page.evaluate(() => window.scrollTo(0, 2000)); await page.waitForTimeout(1000); await page.screenshot({ path: path.join(screenshotDir, '03-services-section.png') }); console.log('✓ 服务区域截图已保存'); // CTA 区域 await page.evaluate(() => window.scrollTo(0, 3800)); await page.waitForTimeout(1000); await page.screenshot({ path: path.join(screenshotDir, '04-cta-section.png') }); console.log('✓ CTA 区域截图已保存'); // 整页截图 await page.evaluate(() => window.scrollTo(0, 0)); await page.waitForTimeout(500); await page.screenshot({ path: path.join(screenshotDir, '00-full-page.png'), fullPage: true }); console.log('✓ 整页截图已保存'); await browser.close(); console.log('\n所有截图已保存到 /tmp/screenshots/ 目录'); })();