screenshot.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. import { chromium } from 'playwright'
  2. const browser = await chromium.launch()
  3. const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } })
  4. const page = await ctx.newPage()
  5. const errors = []
  6. page.on('pageerror', e => errors.push('PAGEERROR: ' + e.message))
  7. page.on('console', m => { if (m.type() === 'error') errors.push('CONSOLE: ' + m.text()) })
  8. await page.goto('http://localhost:8080/')
  9. await page.waitForTimeout(500)
  10. await page.fill('input[placeholder="请输入账号"]', 'admin')
  11. await page.fill('input[placeholder="请输入密码"]', '123456')
  12. await page.click('button.login-btn')
  13. await page.waitForTimeout(1500)
  14. await page.screenshot({ path: 'scripts/shot-equity.png' })
  15. const pages = [
  16. ['#/customization/hsbc/crowd-tasks', 'crowd-tasks'],
  17. ['#/customization/hsbc/tags', 'tags'],
  18. ['#/customization/hsbc/rule-groups', 'rule-groups'],
  19. ['#/customization/hsbc/equity-grant-campaign', 'grant-campaign'],
  20. ['#/customization/hsbc/pages/home', 'page-home'],
  21. ['#/customization/hsbc/equity-products/add', 'add-equity'],
  22. ['#/customization/hsbc/sms-templates', 'sms-templates'],
  23. ]
  24. for (const [hash, name] of pages) {
  25. await page.goto('http://localhost:8080/' + hash)
  26. await page.waitForTimeout(1500)
  27. await page.screenshot({ path: `scripts/shot-${name}.png` })
  28. }
  29. console.log('ERRORS:', errors.length)
  30. errors.forEach(e => console.log(' -', e))
  31. await browser.close()